[antlr-interest] [C runtime] don't compare pointer for negativereturn values !

Jim Idle jimi at temporal-wave.com
Sat Aug 25 10:30:13 PDT 2007



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Holger Schurig
> Sent: Friday, August 24, 2007 4:26 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] [C runtime] don't compare pointer for
> negativereturn values !
> 
> In the examples there is a file examples/C/main.c which contains
> this code:
> 
>    input       = antlr3AsciiFileStreamNew(fName);
> 
>    // The input will be created successfully, providing that
>    // there is enough memory and the file exists etc
> 
> 
> That is utterly nonsense.
>

Errr, thanks for your delicate comments. As I said earlier, I cast the
pointer to unsigned by accident in the examples and thy just need
changing to signed.
 
> Second: the return value for antlr3AsciiFileStreamNew() is a
> pointer. Comparing this for < 0 is nonsense again, because the
> c-runtime could as well give you back 0xD00C0020 as address for
> this pointer. This, seen as a signed value, would be smaller
> than zero. Yet the object has been successfully created.

Yep - I know. However, the functions you call already catch this and
specifically return -1 and -2, which will not be valid pointers.

> 
> 
> 
> So the whole interface idea isn't sane.  You can't really, in a
> platform independend way, encode return values into
> pointer-returning functions.
> 
> Suggestion:
> 
> All the xxxxxNew()-Functions that normally return a pointer

Suggestion - why don't you write your own as you know everything?

Jim


More information about the antlr-interest mailing list