Thread: 16 bit compilar or 32 bit compilar

  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35

    16 bit compilar or 32 bit compilar

    hi,

    i have a doubt on compilation on 16 bit/32 bit.
    Code:
    main()
    {
       unsigned int a=30;
       int b=5;
       c=a+b;
    
       return 0;
    }
    what is the output on 16 bit /32 bit compilar.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    main should return int.
    c is undeclared.
    Last edited by Elysia; 12-03-2007 at 03:10 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    c is undefined.
    you mean undeclared

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by robwhit View Post
    you mean undeclared
    Oops

  7. #7
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35
    Quote Originally Posted by rajkumarmadhani View Post
    hi,

    i have a doubt on compilation on 16 bit/32 bit.
    Code:
    main()
    {
       unsigned int a=30;
       int b=5;
       int c;
       c=a+b;
       printf("%d",c);
    
       return 0;
    }
    what is the output on 16 bit /32 bit compilar.
    here what i mean is, will 'c' give same value on 32/16 bit compiler ? or there makes any difference.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  9. #9
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35
    Is it possible to emulate 16 bit compiler or 32 bit compiler in linux environment by using gcc ?

  10. #10
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by rajkumarmadhani View Post
    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

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rajkumarmadhani View Post
    Is it possible to emulate 16 bit compiler or 32 bit compiler in linux environment by using gcc ?
    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.

  12. #12
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by matsp View Post
    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.
    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.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  14. #14
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    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).

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    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).
    Oh, sure - but OP asked if it was possible to EMULATE 16-bit on a 32-bit [or 64-bit] Linux + gcc environment.

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. counting 16 bit number from a buffer
    By baccardi in forum C Programming
    Replies: 4
    Last Post: 02-20-2009, 03:28 PM
  2. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 07:24 AM
  3. 32 bit or 16 ???
    By GiraffeMan in forum C Programming
    Replies: 11
    Last Post: 04-24-2002, 12:56 PM
  4. 16 Bit Compiler
    By Jperensky in forum C Programming
    Replies: 5
    Last Post: 03-29-2002, 03:08 PM
  5. 16 bit colors
    By morbuz in forum Game Programming
    Replies: 13
    Last Post: 11-10-2001, 01:49 AM