const vs. #define

Ed McNierney ed at TOPOZONE.COM
Thu Oct 19 13:30:36 EDT 2006


Mateusz -

Could you give an example of an error that would be detected using const
that would not be detected using #define?  I agree with your premise in
theory, but I'm not sure how that theory applies here.

	- Ed

-----Original Message-----
From: Mateusz Loskot [mailto:mateusz at loskot.net] 
Sent: Thursday, October 19, 2006 12:27 PM
To: Ed McNierney
Cc: MAPSERVER-DEV at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-DEV] const vs. #define

Ed McNierney wrote:
> I can't imagine it makes any detectable difference in the generated 
> code.

If C compiler supports C99 and const qualifier is well supported, using
const than #define should be preferable.
const is language implementation feature, but #define is a preprocessor
feature.
const as a langauge feature, is "detectable" by compiler, so it's faster
to find bugs when misused.
I think it's always worth to use compiler for bugs detection wherever
it's possible.

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net



More information about the mapserver-dev mailing list