Porting C to Various Platforms

This is a discussion on Porting C to Various Platforms within the C Programming forums, part of the General Programming Boards category; HI Guys I am working at C project. My task is to port this c made application to different platforms ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    1

    Question Porting C to Various Platforms

    HI Guys

    I am working at C project.
    My task is to port this c made application to different platforms like Linux,Unix,Solaris etc.

    I am looking fwd some resources.

    So can anybody help me out?

    Thanks

    Aniruddha

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Should not be difficult at all to port a C application. The real question to ask is what graphics libraries did you use, and there lies let obsticle. You can't port API's because they are vendor specific, unless it is pure Win32 than you can use it on any Microsoft version. The C language definition is supported on most every system though, but this is just the basic definition C99 or ANSI C.

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Conditional Compilation
    1978 Silver Anniversary Corvette

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    It shouldn't be too hard to port a C application. I don't know what kind of application it is. But I guess a great amount of the code doesn't need to be ported.

    Search for those parts of the code which are platform-dependent and find out how the several platforms handle those functionalities. Perhaps some libraries are available for other platforms too.

    I think it's a good idea to organise the code in such a way that platform-dependent code can be put apart. When going to a different platform you then only need to turn some compiler switches on or off.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    ANSI ISO IEC 9899 is the current C standard. You could get a copy of this e-document. I just plan on using .NET though for my cross platform work, because than I can use graphics libraries but when you think of porting the basic definition it shouldn't be too difficult, you have to keep in mind the vendors implimentation (compiler) and like I mentioned API's. Without an execution environment like .NET or Java Virtual Machine, you will have major problems porting sophisticated applications.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    The C language definition is supported on most every system though, but this is just the basic definition C99 or ANSI C.
    Hmm... C99 is hardly a "basic definition." It defines the whole C language. It dictates how C acts and how compilers should act. C99 is ANSI C, so I find it strange that you say C99 or ANSI C. Kind of like saying a cat or a feline isn't it?

    There are two really good ways I can think of to make your code more portable/ easier to port. Actually 3, but one only works in best case situations. You could do like Garfield said and use conditional compilation. It would have helped maybe more if he explained what that was, so I am going to assume he meant using compiler directives like #if and #ifdef to tell the compiler how to compile your code depending on what system/compiler you are compiling for. Secondly you could use an abstaction layer. Take all the code that is not ANSI portable and put them into functions in a separate file, say foo.c. Make the corresponding foo.h file with function prototypes, then make a separate foo.c file for ever system/compiler you wish to port your program to. Then all you have to do is include the correct .c file in your project and you are off to the races. The .h file should work for any system if you did it right because all it should have is prototypes of the functions, which if you don't want to have to play around with your source code too much should all have the same prototypes. This is only a small description of abstraction, but I am sure you can find a more indepth walk-thru or tutorial. The final option is to, if possible, write it all in ANSI compliant C, then you are guaranteed that it will be 100% portable to any system with an ANSI C compiler... which I can't think of one system without one... ok I guess the commador 64...
    one fish two fish
    red fish blue fish

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >The final option is to, if possible, write it all in ANSI compliant C, then you are guaranteed that it will be 100% portable to any system with an ANSI C compiler

    This is rather difficult, assuming you've made the distinction between conforming and strictly conforming when it comes to following the ANSI/ISO guidlines.
    Strictly conforming is as follows:
    - The program only uses features specified in the ANSI/ISO standard
    - The program doesn't exceed any implementation defined limit.
    - The program has no output that depends on implementation defined, unspecified, or undefined features.

    A strictly conforming program is maximally portable and has the same output on any system.

    A conforming program can depend on nonportable features. Which means that it's conforming in the specific implementation but could be non-conforming on another compiler. For the most part programs are conforming more often than strictly conforming.

    The goal of course is to be strictly conforming and still manage to get the program to do what you want. This post is really irrelevant though because it doesn't matter when you get down to it as strictly conforming and conforming are considered the same in most circles. I just felt the need to elaborate a bit.

    -Prelude
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    I meant strictly conforming... anyways I said that it wasn't the easiest or necessarily the desired method of approach, I was only listing it amoung the options. Good point though...
    one fish two fish
    red fish blue fish

  9. #9
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I don't think you will get far with this. As far as I've seen only *NIX follows the ANSI or C99 standard. I think that the only way to accomplish fully portable code is to use an intermediate language and build a common language runtime execution environment.

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    You havn't looked very hard. Borland, DGJPP(which uses gcc for windows/dos programs), MSVC++, and a few others all have options you can flag to get full ANSI Compliance.... it is only as simple as reading your documentation....
    one fish two fish
    red fish blue fish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Platforms
    By okinrus in forum Game Programming
    Replies: 0
    Last Post: 04-05-2004, 06:11 PM
  2. Checking Platforms
    By Elrek in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2004, 06:16 PM
  3. Porting to FreeBSD
    By Beastie in forum Linux Programming
    Replies: 1
    Last Post: 06-15-2003, 08:37 PM
  4. Porting app from c to c++
    By GUI_XP in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2002, 03:31 PM
  5. Porting the NES emulator from DOS to Linux
    By billholm in forum Game Programming
    Replies: 14
    Last Post: 08-03-2002, 02:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21