1

There are several questions and aswers about this question on this site. I tried the answers (including header-files) given, they don't solve my problem.

I migrated my project from VS2013 to VS2015. After compiling i'm getting the error : "C2065 'NULL': undeclared identifier". This didn't happen in VS2013. When I go to my code and 'hover' over "NULL", a window is shown "#define NULL 0". I can right-click on NULL and open "peek definition". The file vcruntime.h is opened and it shows the definition of NULL. (This file is marked as read-only.)

Why do I keep getting this error for every occurence of NULL (+200 times)?

Edit :

#ifndef NULL
   #ifdef __cplusplus
      #define NULL 0
   #else
      #define NULL ((void *)0)
   #endif
#endif
pistach
  • 391
  • 1
  • 4
  • 19
  • @Serhio It is perfectly valid C. Where did you get that idea from? – Lundin Aug 12 '16 at 09:08
  • @Serhio IIRC `#define NULL 0` is standard for C. Why wouldn't it be? – Magisch Aug 12 '16 at 09:14
  • 1
    @Lundin [7.17](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) "... which expands to an implementation-defined null pointer constant ..." . Doesn't it mean that such constant should have pointer type like `((void *)0)` ? – Sergio Aug 12 '16 at 09:15
  • 1
    @Serhio 6.3.2.3/3: "An integer constant expression with the value 0, or such an expression cast to type `void *`, is called a *null pointer constant*." – melpomene Aug 12 '16 at 09:22
  • @melpomene Yes, my bad. – Sergio Aug 12 '16 at 09:24
  • @Serhio You are confusing null pointers and the NULL macro. [Read this](http://stackoverflow.com/a/32136460/584518) – Lundin Aug 12 '16 at 09:29
  • "*a window is shown "#define NULL 0".*" so you seem be using the C++ compiler not the C one, right? – alk Aug 12 '16 at 09:34

1 Answers1

1

Probably you don't include the .h files, or the compiler is not seeking the appropriate folder. Take a look at this Microsoft docs article.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Alexi
  • 389
  • 1
  • 8
  • In de Directories i included (VC++ Directories : .../Windows Kits\10\Include\10.0.10586.0\ucrt\) is one of the header-files suggested in the MSDN article : CRTDBG.H . In this headerfile there is "#include " . This headerfile contains the definition of NULL. The problem is this header-file is already included in my project, i still get the error ... This definition however is grayed out (after ifndef NULL) which probably means it's already defined somewhere else. – pistach Aug 12 '16 at 11:45