I'm struggling with this:
I have vendor-supplied C++ code that I don't want to alter. It fails to compile its code such as
void foo (int alpha, uint8_t *p = NULL); // func prototype in .h file, method of a class.
Mostly to set the default for a parameter while declaring a function prototype in the C++ .h.
But today's C++ conventions define NULL as _NULL via <stdio.h> This enables each compiler vendor to define _NULL to suit, rather than the old value of 0. Motivation seemed to be gross misuse of NULL as 0 in pointers. Some implementations just define _NULL as 0. Others define it as a pointer to 0. The latter is what I struggle with, as C++ conventions for 0 differ from a pointer to a 0 such that an error is thrown for the line of code, above.
And stdio.h is usually not #included by generic library code as above. So, the library code has an #ifndef NULL and then defines it as a pointer, not a 0.
I watched the order of compilation of .c and .c++ files in this large project, 2 files are mine. Luckily, one of my files is first to compile. So I put #include <stdio.h> in my file and errors go away. But it's a kludge.
I don't know by what rationale the IDE (not a Makefile) chooses which file compiles first.
What's the right way to deal with all this so the not-my-library code will compile without error?
And... what's the modern/proper way to give 0 as the default value for a pointer parameter in a C++ function? (as the None type is in other languages). Maybe people use nullptr, so I've read, and stopped using NULL. But I can't prudently change what's in this vendor's code - used by thousands.
I have vendor-supplied C++ code that I don't want to alter. It fails to compile its code such as
void foo (int alpha, uint8_t *p = NULL); // func prototype in .h file, method of a class.
Mostly to set the default for a parameter while declaring a function prototype in the C++ .h.
But today's C++ conventions define NULL as _NULL via <stdio.h> This enables each compiler vendor to define _NULL to suit, rather than the old value of 0. Motivation seemed to be gross misuse of NULL as 0 in pointers. Some implementations just define _NULL as 0. Others define it as a pointer to 0. The latter is what I struggle with, as C++ conventions for 0 differ from a pointer to a 0 such that an error is thrown for the line of code, above.
And stdio.h is usually not #included by generic library code as above. So, the library code has an #ifndef NULL and then defines it as a pointer, not a 0.
I watched the order of compilation of .c and .c++ files in this large project, 2 files are mine. Luckily, one of my files is first to compile. So I put #include <stdio.h> in my file and errors go away. But it's a kludge.
I don't know by what rationale the IDE (not a Makefile) chooses which file compiles first.
What's the right way to deal with all this so the not-my-library code will compile without error?
And... what's the modern/proper way to give 0 as the default value for a pointer parameter in a C++ function? (as the None type is in other languages). Maybe people use nullptr, so I've read, and stopped using NULL. But I can't prudently change what's in this vendor's code - used by thousands.
Last edited: