views:

106

answers:

6

Hi,

I'm working with an old C code that still has a few dusty corners. I'm finding a lot of #ifdef statements around that refer to operating systems, architectures, etc. and alter the code for portability. I don't know how many of these statements are still relevant today.

I know that #ifdef isn't the best idea in certain circumstances, and I'll be sure to fix that, but what I'm interested in here is what's being tested.

I've listed them below. If you could tell me if any of them are definitely useful in this day and age, or if the machines or OSs with which they're associated have long since expired, that would be great. Also, if you know of any central reference for these, I'd love to hear about it.

Thanks in advance, Ross

BORLANDC
BSD
CGLE
DRYRUN
HUGE
IBMPC
MAIN
M_XENIX
OPTIMIZED
P2C_H_PROTO
sgi
TBFINDADDREXTENDED
UNIX
vms
__GCC__
__GNUC__
__HUGE__
__ID__
__MSDOS__
__TURBOC__
+7  A: 

Here you are.

Alexandre C.
+1 for the link
neuro
+10 for the link. who's more ;) P.S. throwing in to the pile: `echo | gcc -dM -E -`. that is a GCC trick to dump all defines set by the preprocessor itself.
Dummy00001
+3  A: 

You are coming from the wrong direction. Instead of asking what code can be safely deleted, you should ask - what code have to stay.

Find out what platforms have to be supported and delete everything that is not defined in any of them. You'll get yourself cleanest code possible that is still guaranteed to work.

vava
+1  A: 

Any #ifdef based on arbitrary preprocessor definitions provided by the implementation is outdated - especially those which are in the namespace reserved for the application, not the implementation, as most of those are! The correct modern way to achieve this kind of portability is to either detect the presence of different interfaces/features/behavior with a configure script and #define HAVE_FOO etc. based on that, directly test standard preprocessor defines (like UINT_MAX to determine integer size), and/or provide prebuilt header files for each platform you want to support with the appropriate HAVE_FOO definitions.

The old-style "portability" #ifdefs closely coupled knowledge of every single platform all over your source, making for a nightmare when platforms changed and adopted new features, behaviors, or defaults. (Just imagine the mess of old code that assumes Windows is 16bit or Linux has SysV-style signal()!) The modern style isolates knowledge of the platform and allows the conditional compilation in your source files to depend only on the presence/absence/behavior of the feature it wants to use.

R..
+1  A: 

Code that is annotated like that can in fact be quite difficult to maintain. You could consider to look into something like autotools or alike to configure your sources for a particular architecture.

Jens Gustedt
Indeed. I'm currently building the code with automake, but have yet to figure out exactly how to work the in this kind of functionality.Much to do…
rossmcf
yes, this is not completely trivial, I agree. try perhaps to move all your architectural dependencies in one (or few) file, and move from there.
Jens Gustedt
+2  A: 

What context is this code being used?

  1. If it's a library other people outside your organization are using, you shouldn't touch this stuff unless you're releasing a new version and explicitly removing support for some OSs. In the latter case, you should remove all the relevant IFDEF code as part of making a new release, and should be explicit about what you are removing.
  2. If it's a library people inside your organization are using, you should ask those people what you can remove, not us.
  3. If it's code being used very narrowly (i.e. you control its use directly), you can, if you wish, safely remove any sort of compiler portability, since you are only using one compiler.
Brian
Thanks Brian. There are no existing users whose work will be disrupted by the removal of support, however the code may be used on a range of machines, beyond my control. Each user will build the code from source with whatever C compiler they have locally.I want to keep to the minimal set of options, and only for popular, modern compilers.
rossmcf
+2  A: 

You're asking the wrong people: It's your users (or potential users) who decide what's still useful, not us. Start by finding out what platforms you need to support, and then you can find out what's not needed.

If, for example, you don't need to support 16-bit systems, you can dispense with __HUGE__, __MSDOS__, and __TURBOC__.

dan04