Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using 'const' in C, what porting trouble might that cause?

I would like to use 'const' in C interface functions to note that certain char * arguments are not modified by the function.

What trouble might this cause in porting this code to various platforms? Is support of 'const' in C code pretty standard? When did this become officially in C standard?

like image 548
WilliamKF Avatar asked Dec 07 '22 20:12

WilliamKF


1 Answers

I can't imagine const not being supported by any compilers, so porting should be a non-issue. If you were to find such a beast, you could just put

#define const

Somewhere in a common header file to make all of the const keywords vanish. The runtime semantics of your program won't change at all (since your compiler didn't support the keyword anyway).

like image 87
Carl Norum Avatar answered Jan 05 '23 16:01

Carl Norum