tags:

views:

126

answers:

4

Hi, I have a very simple question.

I want to write the below line of code in 2 lines :

IplImage *image = 0;

like :

IplImage *image;
image = 0;

I want to know what I have written is correct or else I want to know how to write the correct one (in two lines).

Thanks

+1  A: 

It is correct. Why didn't you just try it?

Job
Well, the argument could be made that most every compiler has extensions; just because it works doesn't mean it's valid according to the standard.
Billy ONeal
+5  A: 

Perfectly correct. But if you don't have a very good reason to do it that way, I'd suggest leaving it as a single line that both declares and initializes it. It's more obvious, and you're less likely to ever miss initializing a pointer that way.

Head Geek
+1  A: 

Writing

IplImage *image = 0;

seem to be clearer as it is obvious that a pointer is used.

With

IplImage *image;
image = 0;

you may have additional lines of code between the first and the second line. The second line (image = 0) appears less clear to me. Maybe renaming the variable to pImage improves readability if you prefer the second option (two liner).

John
A: 

Iplimage is the structure defined in opencv. You can use code below to initialize the pointer:

Iplimage* image=cvCreateImage(width,height,channels);
kit.yang