c++cconditional-compilationsun

Any way to detect SparcWorks on SunOS?


I've got a legacy C++ code base which includes the following:

// this kludge is required because SparcWorks 3.0.1 under SunOS
// includes malloc.h in stdlib.h, and misdeclares free() to take a char*, 
// and malloc() and memalign() to return char*

Clearly this is some leftover from ancient C. The comment is followed by prototypes (wrong here on Fedora Linux 39, they clash with the ones glibc-2.38-18 has). I'd like to #if that part out cleanly. Any macro that I can use?


Solution

  • You could try to use both these macros:

    #if defined(__SUNPRO_CC) && defined(__sun)
    // Specific code for SparcWorks compiler on SunOS
    #else
    // Code for other compilers or platforms
    #endif
    

    Maybe useful reference: Sun™ Studio 12: C++ FAQ