Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5362

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 5362

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>