LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Missing 'const' causes no compile error in some cases - maybe give a warning then?

These two cause errors:

 

extern int const constint_var;

// error: redefinition of 'constint_var' with a different type
int constint_var;

 

void test_constint_ptr(int const *i);

// error: conflicting types for 'test_constint_ptr'
void test_constint_ptr(int *i) { *i = 3; i = NULL; }

 

But the following not:

 

void test_constint(int const i);

// NO ERROR
void test_constint(int i)
{
  i = 3;
}

 

void test_int_constptr(int *const i);

// NO ERROR
void test_int_constptr(int *i)
{
  *i = 3;
  i = NULL;
}

 

I see that the ones which don't cause an error have no impact on the caller and thus it doesn't matter to them (and the compiled code there) if the functions modify their local values.

 

Yet I find this confusing because the prototype doesn't match the function. A compiler warning would be nice, like Visual Studio has.

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 1 of 3
(4,231 Views)

Hi CVI_User,

 

could you please post the compiler messages for the error cases, too?

 

Which CVI version do you use?

 

Best regards,

Melanie

Best regards,
Melanie Eisfeld
Senior Applications Engineer, National Instruments Germany
Certified LabVIEW Developer
Certified TestStand Architect
0 Kudos
Message 2 of 3
(4,209 Views)

The error messages of Clang (CVI 2013 SP1) are already included in the comments inside the code samples.

It's not a bug report, I'd just like to know what others think of this.

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 3 of 3
(4,164 Views)