[antlr-interest] C runtime const correctness

Gary R. Van Sickle g.r.vansickle at att.net
Tue Dec 2 19:38:22 PST 2008


> From: Jim Idle
> 
> On Mon, 2008-12-01 at 22:17 -0600, Gary R. Van Sickle wrote: 
> 
> 	
> 	Shouldn't this:
> 	
> 	    ANTLR3_API pANTLR3_INPUT_STREAM 
> antlr3AsciiFileStreamNew(pANTLR3_UINT8
> 	fileName);
> 	
> 	Really be this:
> 	
> 	    ANTLR3_API pANTLR3_INPUT_STREAM 
> antlr3AsciiFileStreamNew(const
> 	pANTLR3_UINT8 fileName);
> 	
> 	?
> 	
> 
> Not all C compilers support that as it is , though I suspect 
> that for other reasons, a C compiler that did not probably 
> would not compile the runtime anyway.

*Now* do you believe me when I say it's not really the 21st century? ;-)

I'm not quite sure what you mean though.  It sounds like you're saying these
olde-tyme compilers can't even handle that without the constification of the
pointer.  If that's true, well, what's another mouthful of water when you're
already drowned?

But I suspect you're really talking about compilers not supporting const.
Well, yeah, back in the Cretaceous they didn't, but:

1.  That's what "#if IM_A_CRUSTY_OLD_COMPILER/#define const/#endif" was
invented for.
2.  You're already using const on lines 428 and 434 of the same header.

> So strictly speaking 
> yes, but I would not spend too much time worrying about this :-)
> 

Granted, such time would be better spent on getting my kickin'-it-oldschool
autotools+script-fu installer and command-line-helper contributed ;-), but
const-non-correctness forces me to worry about it, because now not only do I
have to do this in my C++ program (which is bad enough, but that's
Stroustrups' fault):

	input = antlr3AsciiFileStreamNew(input_files[i].c_str()); //
input_files is a vector of strings.

...but I have to cast away string::c_str()'s const-ness, thus:

	input =
antlr3AsciiFileStreamNew((pANTLR3_UINT8)(input_files[i].c_str()));

...which I think we can all agree is quite unbecoming a 20th century
computer language.

So anywhoo, please take it under advisement the next time you're in there.

Now, how the heck do I contribute this awesome autotools/script action I got
going on here?  Lessee... "ANTLR contributors certificate of origin"...?
Snailmail...?  "Fax"...?  Do fax machines even exist anymore?  Grumble, I
was sort of hoping the whole BSD license thing would have covered all the
necessary legalities :-/.

> Jim 
> 

-- 
Gary R. Van Sickle
 



More information about the antlr-interest mailing list