Thread: Cross (compiler | OS) && reuseable code

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Talking Cross (compiler | OS) && reuseable code

    Hello guys, here I come with a new problem!
    *sigh* such a trouble-maker... *_*"


    1. Btw, is there any tips to make our code reuseable?

    2. How to organize it well?

    For example, we have the header file "memoryPool.h", the source "memoryPool.c" and the OOP templated class C++ version "memoryPool.cpp"

    3. Where we should put those files? Should we put those file in: project-directory\include or compiler-directory\include?

    4. How about if we are working on different compilers?


    5. Anybody know what is the indicated #defines that we are now working on:
    - GCC / MinGW
    - LCC
    - TCC
    - eC
    - Digital Mars C++
    - Microsoft Visual C++ 6/2005/2008
    - Pelles C
    - Bloodshed Dev-C++ == MinGW?
    - Borland C++ 5.5/2005/new version?


    And the last question, ...

    6. How to know if our code is cross platform?

    7. Should we test it on different OS(es)?

    8. Or is there any #defines?


    Btw, thanks in advance. phew...
    Last edited by audinue; 07-21-2008 at 11:02 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    3. Nothing should ever ever ever ever ever ever ever ever ever ever ever ever go in your compiler directory (except the compiler itself).

    5. What do you mean?

    6. You look at it. If you're using system(), or any API functions that only exist on one/some platform, then you're stuck. Otherwise it should be portable.

    7. If you want it to work on more than one OS, yes. Otherwise, why bother?

    8. For what?

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    I think for 5 he means like #ifdef MINGW if it's being compiled in mingw.

    As for 8 there is #ifdef WIN32

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > 1. Btw, is there any tips to make our code reuseable?
    > 2. How to organize it well?
    Understand the difference between
    a) ANSI
    b) POSIX
    c) Platform specific.
    Don't mix APIs from different domains in the same code. Ideally, 90% of the code should be code you've written and ANSI. Isolate the rest in "compatibility" layers which will minimise the amount of rework in case you need to port from one system to another.

    > 3. Where we should put those files? Should we put those file in: project-directory\include or compiler-directory\include?
    NEVER in the compiler include directory.
    If you're writing a library which others will use, then it would go (in Unix terms) into /usr/local/include and /usr/local/lib

    > 4. How about if we are working on different compilers?
    Always a good idea
    It keeps you honest and stops you slipping in any implementation defined or specific compiler extensions.

    > 5. Anybody know what is the indicated #defines that we are now working on:
    http://predef.sourceforge.net/

    > 6. How to know if our code is cross platform?
    By trying it on various systems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Oops.. I forget!

    9. Are std* functions portable?

    ^_^" Thank you for your response, that's very very help me so much.

    Anybody know what is the indicated #defines that we are now working on <-- bad grammars?

    *OMG* http://predef.sourceforge.net/precomp.html There are a LOT of compilers out there!!
    Last edited by audinue; 07-22-2008 at 02:39 AM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by audinue View Post
    Oops.. I forget!

    9. Are std* functions portable?
    You mean stuff like stdio.h, stdlib.h, time.h etc: yes, from a calling perspective they are. That's not to say that stdio.h functions can't contain extensions that are non-portable [e.g. printf() supports %b for binary or some such, whilst most other compilers don't - a more common example would be the fflush(stdin) that actually does clear the input buffer, whilst the standard only says that it will flush ouput data].

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

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You mentioned C++, so if you mean all of the stuff in the std:: namespace, yes, that is generally portable too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hp iPAQ 6300 && C compiler || C# compiler
    By xddxogm3 in forum Tech Board
    Replies: 2
    Last Post: 12-07-2004, 07:28 AM
  2. Combining C && C++ Code
    By drtriedl in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 01:48 PM
  3. Replies: 4
    Last Post: 01-16-2002, 12:04 AM
  4. Replies: 3
    Last Post: 11-04-2001, 03:53 PM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM