hey guys

ive made a project in vs2010 that has a hardcoded (int val; val=800000; in main) amount set at start , the amount is 800000 (800k) i gave it an int type , and it works all well but when i try to run it in the anicent turboc i need to for school , it will flip out and give gibberish values above 15000 (15k) somthing i realise this is because in vs2010 the default int has a larger memory ? ive tried giving a double type in tc but didnt work out ... it will show correct value at 800000 if i use a float tho , but its described the program has to use in for that specific value ...

Edited by TomaCukor: n/a

6 Years
Discussion Span
Last Post by Narue

Turbo C is a 16-bit compiler, which essentially means that the actual range of int is [32,767, -32,768] (16 bits, two's complement). It simply can't handle 800000, but long can. The fix in your case is to change your code to use long instead of int.

As a side note, for maximum portability it's best to use int only when the values are guaranteed to be within the range of [32,767, -32,767] (ie. 16 bits). For anything beyond that, use long (up to a range of 32 bits). The reason is that these are the minimum ranges specified in the C standard. You're absolutely guaranteed to have at least that much, but any more is implementation-dependent.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.