Thread: How to know if my code is ANSI strict ?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    111

    How to know if my code is ANSI strict ?

    Hello,..

    after few posts (here and on some other forums) i realized that i need some way to know if some code is ANSI or not (not every thing that is Posix will work on Windows Platforms and back).

    im working for a few weeks on SMSer (smser.sf.net) and my next goal in that progect is to make it as ANSI as possible the question is how ?

    for now (Revison 23 The code wasn't uploaded yet) i find all system calls and posix spesifc and search for ecualent function in ANSI but is there and automatic way to that ?
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Compiling with
    gcc -W -Wall -ansi -pedantic prog.c
    goes a long way to making sure your code is ANSI-C

    Inevitably, you'll need some dependencies on the outside world to interact in a meaningful way with real systems, so some of your code will not be ANSI-C.

    But the idea is that you encapsulate the dependencies in a small part of the code, to minimise the amount of rework and maintenance.

    An example would be to have say
    PosixPort.c
    Win32Port.c

    A hypothetical function of yours, say myReadDirectory(), would be present in both files. It would call opendir() in PosixPort.c, and FindFirst() in Win32Port.c
    But for the bulk of your code, you only see myReadDirectory().

    You would of course only compile ONE of the Port.c files, depending on the environment you were targeting.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM