hi,
i have a doubt on compilation on 16 bit/32 bit.
what is the output on 16 bit /32 bit compilar.Code:main() { unsigned int a=30; int b=5; c=a+b; return 0; }
hi,
i have a doubt on compilation on 16 bit/32 bit.
what is the output on 16 bit /32 bit compilar.Code:main() { unsigned int a=30; int b=5; c=a+b; return 0; }
The executable suitable for 16/32 bit CPU
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
main should return int.
c is undeclared.
Last edited by Elysia; 12-03-2007 at 03:10 AM.
If by "output" [and assuming that there is a declaration of the variable c] you mean what the program itself would output, rather than what machine code the compiler produces, then I would say "neither 16 or 32-bit code will output anything, as there is no output statement in the code".
And if we continue to ignore the difference in machine code generated [and assume complete code], there is no effective difference for integers of 16 or 32 bit for the calculations you make.
You may get a warning for mixing unsigned and signed integers, but again, the warning is not critical for this particular case, as both values are small positive integers, that combined will fit in a 6-bit number (7 bits for a signed value, as the sign is positive and we need to start the number with a zero).
I'm not sure what type of answer you were looking for... Aside from a missing declaration, there is nothing in this code that makes any difference to it's "effect" on a 16 or 32 bit machine.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
There will be no difference between a 16-bit and 32-bit build of that particular source code.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Is it possible to emulate 16 bit compiler or 32 bit compiler in linux environment by using gcc ?
Probably.
> main should return int.
But it does. -- just not explicitly.
rajkumarmadhani, read http://www.catb.org/~esr/faqs/smart-questions.html
Depends on what you want to "emulate". gcc IS a 32-bit compiler [or 64-bit, but there is usually little to make a difference between 32 and 64-bit], so there's no need at all to emulate that.
If you want to make calculations in 16 bit, you can use "short int" or "short unsigned" instead of "int" and "unsigned", which makes the value 16 bit. There are a few other things that may differe in a 16-bit environment [such as the amount of available memory], which can be a bit harder to emulate.
Describe in further detail what you actually want to achieve, and perhaps we can suggest a solution.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
How about a wrapper for malloc() and an equivalent one for free()? It's the easiest one I can think of off the top of my head.
The difficulty comes in with virtual memory and how much memory you want to assume you actually have. Either way, your wrapper could keep track of memory requests and pretend to only have 0xFFFF bytes or less (or more for systems that have higher addressing... particularly the SNES is a 16-bit system that has 24-bit memory addressing I believe, by way of a separate 8-bit data bank register + whatever 16-bit memory address you use.... although I think certain memory banks are mapped at least one other time in another bank for some reason, so it's not entirely the same thing, but you get the point I hope. ) in total memory for your program to use. It may not be perfect, but it might given you an idea of memory requirements on a given system, especially if you can change the memory wrapper options and limitations at compile-time or runtime in an easy manner.
Overall, though, I would wonder if there is not an easier way to do whatever the OP actually wants.
Sure, you can wrap or replace malloc() & free(). It's not TERRIBLY difficult, but I get the impression from the OP that it's not entirely within his/her grasp.
Not sure tho.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yeah, but just wrapping malloc() & free() won't make it a 16-bit program. Unless I'm mistaken, there's some other info in the .exe that tells the OS (I'm a 16-bit program, or I'm a 32-bit program).
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.