'LONG' to 'int' [modified]
-
I have a LONG variable, x, and I need to use the value as an int for my "for" loop. for (int i; imodified on Monday, June 2, 2008 8:47 PM
Where's the code? :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I have a LONG variable, x, and I need to use the value as an int for my "for" loop. for (int i; imodified on Monday, June 2, 2008 8:47 PM
It should work even as a type long (I'm not familiar with type LONG: if it's a composite type, then it won't work). Any reason you can't just cast it to int at the point you are actually using it within the loop? This should work (provided x is not a composite type)
for( x = someval; x < someotherval; x++ ) { ... i = (int)x; //cast x to int where it's actually needed. }
David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------
-
Where's the code? :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I have a LONG variable, x, and I need to use the value as an int for my "for" loop. for (int i; imodified on Monday, June 2, 2008 8:47 PM
When I compile this code, it compiles with no errors (Visual C++ 6.0) void test(void) { LONG x; x = 800; for (LONG i=0; i < x; i++) { } }
-
I have a LONG variable, x, and I need to use the value as an int for my "for" loop. for (int i; imodified on Monday, June 2, 2008 8:47 PM
-
You shouldn't have to do anything special to use the LONG. There's no requirement to use int in a 'for' statement. You can actually put any valid code you want to in the three expressions (init/condition/loop). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: