On Sat, Feb 23, 2002 at 03:21:08AM -0600, Brian Lee Ray wrote: > > From: "Josh Wilmes" <[EMAIL PROTECTED]>
> > Using NULL where a function pointer is expected is considered an error by > > tcc, and a mandatory warning by lcc. It is my understanding that > conversion > > between data pointers and function pointers is forbidden under ANSI C89. > The relevant excerpt: > Using NULL in this way is perfectly conforming, as it is > expressly allowed by the standard in 6.2.2.3: > > =================== > An integral constant expression with the value 0, or such an > expression cast to type void *, is called a null pointer > constant. If a null pointer constant is assigned to or compared > for equality to a pointer, the constant is converted to a > pointer of that type. Such a pointer, called a null pointer, is > guaranteed to compare unequal to a pointer to any object or > function. > > Two null pointers, converted through possibly different > sequences of casts to pointer types, shall compare equal. > ==================== > Still, if tcc won't take it, there's no sense in whining about it. This > should fix it: Function pointers are not data pointers. [And thinking about it, that excerpt doesn't say that. I hope its context did, else I'd accuse the standard of being unclear] There is some-or-other rather old Cray architecture where they are sufficiently different that casting a function pointer to (void *) and then back to a function pointer was enough to garble the function pointer. [This was a perl5 bug report from 2 or 3 years ago. It was something to do with how source filters were stashing a function pointer in an unused bit of an IO structure, IIRC. It got fixed, with a union, IIRC] > ############################### > diff -ur include/parrot/parrot.h include/myparrot/parrot.h > --- include/parrot/parrot.h Fri Feb 22 18:03:58 2002 > +++ include/myparrot/parrot.h Sat Feb 23 03:03:50 2002 > @@ -76,9 +76,11 @@ > /* define some shortcuts for dealing with function pointers */ > /* according to ANSI C, casting between function and non-function pointers > is > * no good, except in the special case of NULL. So we should use > "funcptr_t" > - * in place of void* when dealing with function pointers*/ > + * in place of void* when dealing with function pointers. Also, some > compilers > + * do the wrong thing when assigning NULL to a function pointer, so we have > to My understanding of C89 would mean that the wording of your comment is not correct. Function pointers are not data pointers, compilers are allowed to warn. [Actually, shouldn't conformant compilers always issue a diagnostic, as you're doing something not allowed by the standard] It seems that your mailer or something on the way has "helpfully" wrapped all the lines in your patch. Don't you just love them? I'd prefer a wording something like this: Also, some very picky ANSI C compilers won't assign NULL to a function pointer, so we have to use NULLfunc instead (mainly because we are wrong and the compilers are not) Nicholas Clark -- EMCFT http://www.ccl4.org/~nick/CV.html