Finite list of things that vary with CPU-type (proper)

Discussion in 'C Programming' started by Tomás Ó hÉilidhe, Dec 4, 2008.

  1. (One dodgy click of the mouse and the previous thread got posted
    prematurely. Here's the proper thread.)

    I would like to draw up a finite list of things you have to "watch out
    for" when compiling a C program for a different kind of CPU than it
    was originally intended for. For instance, let's say you have a C
    program that was intended to run on an x86 processor, but you want to
    compile it on an Apple Mac that has a PowerPC processor.

    Now of course I know a lot of people who frequent this forum aim to
    write fully-portable programs where possible, but at some stage you
    might have the source code for a particular program and want to
    compile it for a different kind of CPU that it was originally intended
    for.

    A good example of this is with Linux. Different binaries of the Linux
    operating system can be gotten for different CPU types, so two
    different computers with two different CPU's can essentially have the
    same operating system. You might download the source code for a
    program which you know runs well on an x86 computer, but you're weary
    that it might contain some non-portable features that will cause it to
    malfunction on your PowerPC. So with that in mind, I'd like to draw up
    a finite list of things that can change with CPU type and that may
    influence a C program.

    Well the obvious ones are:

    1) Integer type sizes and ranges (CHAR_BIT, INT_MAX, sizeof(int),
    etc.) (Yes I realise these are more to do with the compiler, but many
    compilers reflect the underlying machine)
    2) The presence or lack thereof of padding in integer types (it's
    extremely rare as far as I know to have padding in integer types)
    3) The assumption that all-bits-zero is valid for null pointers
    and floating-point numbers (by the way has there ever been a system
    where this wasn't so?)
    4) Byte order in integer types (e.g. little endian, big endian)
    5) Alignment requirements for types.

    If you're writing fully-portable programs, then none of these should
    be a problem. However if you're writing a specialised program, for
    instance a networking program, then you might enforce some non-
    portable assumptions; for instance a common assumption in networking
    programming is that CHAR_BIT == 8.

    You might come across a program that assumes the CPU to be little
    endian, and this will be a problem if the program does networking.

    I can't think of any more thing off hand to watch out for, but the
    reason I'm posting here is that I get the feeling there could be a big
    one that I hadn't thought of. If anyone can think of anything to watch
    out for, please reply.
     
    Tomás Ó hÉilidhe, Dec 4, 2008
    #1
    1. Advertising

  2. Tomás Ó hÉilidhe

    Ian Collins Guest

    Tomás Ó hÉilidhe wrote:
    >
    > I can't think of any more thing off hand to watch out for, but the
    > reason I'm posting here is that I get the feeling there could be a big
    > one that I hadn't thought of. If anyone can think of anything to watch
    > out for, please reply.


    Have you read (as suggested earlier) Annex J of the standard?

    --
    Ian Collins
     
    Ian Collins, Dec 4, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Moore

    Vary by custom

    Ryan Moore, Jan 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,710
    GeekyMonkey
    Aug 24, 2006
  2. HeroOfSpielburg
    Replies:
    1
    Views:
    393
    Alf P. Steinbach
    Aug 6, 2003
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    604
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  4. Tomás Ó hÉilidhe

    Finite list of things that vary with CPU-type

    Tomás Ó hÉilidhe, Dec 4, 2008, in forum: C Programming
    Replies:
    16
    Views:
    616
    Ben Bacarisse
    Dec 7, 2008
  5. Borked Pseudo Mailed

    Finite list of things that vary with CPU-type

    Borked Pseudo Mailed, Dec 4, 2008, in forum: C Programming
    Replies:
    2
    Views:
    314
    Bartc
    Dec 6, 2008
Loading...

Share This Page