Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Initialization of pointer to pointer to int

Here is the sample code that I ran on Visual Studio 2010:

#include <iostream>

int main()
{
    int **p(NULL);
}

I get this error: error C2059: syntax error : 'constant'

But if I change int **p(NULL); to int **p = NULL; the above code compiles fine.

Checked this on GCC(Version:4.4.2) and both work fine. What am I missing here?

like image 313
omggs Avatar asked Jun 21 '12 09:06

omggs


1 Answers

VC++ compiler seems confused about initializations of pointer to pointer ...

This works for example

int (**p)(NULL);

These don't

int *i;
int **p(&i);
int **o(NULL);

This works though

int (**p)(&i);
typedef int* intp;
intp *o(NULL);

etc... the pattern is initialization fails whenever two ** are present! I'd guess a bug! Someone from MSVC team might be able to confirm

like image 61
hawk Avatar answered Oct 19 '22 13:10

hawk