This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280040-Q1: Driverlib NULL definition in C++ application

Part Number: TMS320F280040-Q1

Hello folks,

I'm writing a C++ project and reusing some C++ classes from previous projects based on other microcontrollers.

Since the DriverLib is, as far as I know, written in C the NULL pointer is defined in hw_types.h as follows:

//****************************************************************************
//
// For checking NULL pointers
//
//****************************************************************************
#ifndef NULL
#define NULL ((void *)0x0)
#endif

However, this definition is not being accepted by the compiler and when I replace the NULL by a constant 0 (zero) it works fine. (Based on a quick google on this issue, in C the macro NULL may have the type void*, but that is not allowed in C++).

My question: is there a simple way to overwrite the NULL definition from DriverLib (in hw_types.h)? I would prefer don't change the library files locally. 

I have on my code the following definition for NULL

#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif

However, it does not overwrite the NULL definition present on  hw_types.h.

Any help would be very appreciated. Thank you.

  • However, it does not overwrite the NULL definition present on  hw_types.h.

    Is your definition seen first in the source file before any driverlib include?

    Since C includes can nest, your definition would need to appear prior to any driverlib include, or any of your include files which may include driverlib.

    The TI C2000 compiler has the --preinclude option to allow file(s) to be included at the beginning of compilation.

    Perhaps the most robust work-around would be to place the NULL definition it it's own include file, and set the preinclude option in the CCS project to pull-in your include file with the NULL definition.

  • Thank you, Chester, the --preinclude option solved the problem. I've tried to place the driverlib includes after all other includes, but did not work. Thank you for your help.

    Cheers,

    Luciano