0

I have defined the following in a c file:

#ifdef __clang__
// clang definition here
#elif defined _GNULINUX
#define _ALIGNED_FREE(pMempointer)   _free((pMempointer))
#elif defined _MSC_VER
// VS definition here
#else
// default definition
#endif

void * pMemory = 0L;
if(pMemory) {
  _ALIGNED_FREE(pMemory);
}

gcc flags are: -Wall -Wno-long-long -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -pipe -fexceptions -Wpointer-arith -Wcast-align -Wsign-compare -pedantic -mmmx -msse

After compiling (in a Ubuntu 14.04 machine) with gcc version 4.8.2 successfully the program exits at runtime with undefined symbol: _free Obviously the symbol _free is unknown, but why does gcc not complain about this? I would expect it to throw an error at linking time like the VS linker does.

fiscblog
  • 694
  • 1
  • 12
  • 27
  • 2
    The linker would complain, not the compiler. In your case, the dynamic linker is complaining at start of runtime. BTW, compiling with `gcc -Wall -Wextra -Wno-prototypes` might help. – Basile Starynkevitch Mar 11 '15 at 09:17
  • You should edit your question, at least to show the compilation commands and the source code using `_ALIGNED_FREE` – Basile Starynkevitch Mar 11 '15 at 09:19
  • 1
    Can you give a complete reproducible example? (And remove the `#if` branches which aren't used.) – mafso Mar 11 '15 at 11:25
  • `_GNULINUX` and `_ALIGNED_FREE` are [reserved names](http://stackoverflow.com/q/228783/981959) and so it is undefined behaviour to declare anything using those names (that's not the cause of your problem, but stop it anyway). – Jonathan Wakely Mar 11 '15 at 12:32

1 Answers1

0

free does not have a leading underscore in Linux nor by the C Standard.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • We are all aware of this and the question is, why does the compiler not complain sooner. Not what the correct spelling is. – RedX Mar 11 '15 at 09:31
  • Does `grep -rw _free /usr/include` produce anything useful? – chqrlie Mar 11 '15 at 09:38