[Bug c/40627] not following "right-then-left" rule when compiling function pointers

2009-07-03 Thread dj2con at gmail dot com


--- Comment #5 from dj2con at gmail dot com  2009-07-03 15:29 ---

I was still curious, so I re-read section 6.7.5.3 of the standard.  And having
re-read it, I would like to apologize for troubling everyone -- upon re-reading
6.7.5.3, it now seems obvious that I was mis-applying the "right left rule". 
For anyone else who might pop across this exchange in the future, here is the
explanation:

A regular function prototype, for a function named "D",  *must* be of the
format:

T D( parmlist );

If we replace the name "D" with a dereferenced function pointer "d", the
prototype *must* still be of the same format; otherwise it will no longer be
recognized as a function by the compiler.  And if the prototype is no longer
recognized as a function, it is not going to be parsed properly no matter how
compliant it is with any other rules.  Hence, "T (*d)( parmlist );" is valid,
but "T d * ( parmlist )" is not because the compiler should not recognize that
"d *" is a function.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40627



[Bug c/40627] not following "right-then-left" rule when compiling function pointers

2009-07-03 Thread dj2con at gmail dot com


--- Comment #3 from dj2con at gmail dot com  2009-07-03 14:42 ---
(In reply to comment #1)
> (In reply to comment #0)
> > , but it does not seem to recognize that the following is also a valid
> > prototype:
> > 
> > int count * ( demo_counter * self, int count_amt );
> 
> It isn't.
> 
> > Following the traditional "right-then-left" rule, BOTH of these should be
> > parsed as: "count is a pointer to a function which accepts a demo_counter
> > pointer and an int and returns an int.".  But the second one results in a
> > compilation error with gcc.
> 
> After more than 20 years working with C (and with the C language
> specification), I've never seen this supposed "traditional" construct.  My
> experience on Windows is weak; maybe it's some strange Microsoft extension? 
> It's not part of the C language specification.  If you believe otherwise,
> please find a reference for it...
> 

I don't know where you've been hiding for these past twenty years, Ken.  But
the "right left rule" has been around longer than you've been working (and
longer than Microsoft has been in business!).  I would take the time to explain
it to you, but you can google the terms "right left rule" C as easily as I can. 

My experience on Windows is also weak.  But I don't see what that has to do
with the problem at hand.

In another comment Richard Guenther also claimed it is not a valid prototype. 
Richard typically knows what he's talking about, so I'll take his word for it
and assume that the "right left rule" does not apply for some reason in this
particular case.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40627



[Bug c/40627] New: not following "right-then-left" rule when compiling function pointers

2009-07-02 Thread dj2con at gmail dot com
tribute__((__cdecl__)) abs (int);
int __attribute__((__cdecl__)) atexit (void (*__func)(void));
double __attribute__((__cdecl__)) atof (const char *__nptr);



int __attribute__((__cdecl__)) atoi (const char *__nptr);
int __attribute__((__cdecl__)) _atoi_r (struct _reent *, const char *__nptr);
long __attribute__((__cdecl__)) atol (const char *__nptr);
long __attribute__((__cdecl__)) _atol_r (struct _reent *, const char *__nptr);
void * __attribute__((__cdecl__)) bsearch (const void * __key, const void *
__base, size_t __nmemb, size_t __size, int (* __attribute__((__cdecl__))
_compar) (const void *, const void *));




void * __attribute__((__cdecl__)) calloc (size_t __nmemb, size_t __size);
div_t __attribute__((__cdecl__)) div (int __numer, int __denom);
void __attribute__((__cdecl__)) exit (int __status) __attribute__ ((noreturn));
void __attribute__((__cdecl__)) free (void *);
char * __attribute__((__cdecl__)) getenv (const char *__string);
char * __attribute__((__cdecl__)) _getenv_r (struct _reent *, const char
*__string);
char * __attribute__((__cdecl__)) _findenv (const char *, int *);
char * __attribute__((__cdecl__)) _findenv_r (struct _reent *, const char *,
int *);
long __attribute__((__cdecl__)) labs (long);
ldiv_t __attribute__((__cdecl__)) ldiv (long __numer, long __denom);
void * __attribute__((__cdecl__)) malloc (size_t __size);
int __attribute__((__cdecl__)) mblen (const char *, size_t);
int __attribute__((__cdecl__)) _mblen_r (struct _reent *, const char *, size_t,
_mbstate_t *);
int __attribute__((__cdecl__)) mbtowc (wchar_t *, const char *, size_t);
int __attribute__((__cdecl__)) _mbtowc_r (struct _reent *, wchar_t *, const
char *, size_t, _mbstate_t *);
int __attribute__((__cdecl__)) wctomb (char *, wchar_t);
int __attribute__((__cdecl__)) _wctomb_r (struct _reent *, char *, wchar_t,
_mbstate_t *);
size_t __attribute__((__cdecl__)) mbstowcs (wchar_t *, const char *, size_t);
size_t __attribute__((__cdecl__)) _mbstowcs_r (struct _reent *, wchar_t *,
const char *, size_t, _mbstate_t *);
size_t __attribute__((__cdecl__)) wcstombs (char *, const wchar_t *, size_t);
size_t __attribute__((__cdecl__)) _wcstombs_r (struct _reent *, char *, const
wchar_t *, size_t, _mbstate_t *);






void __attribute__((__cdecl__)) qsort (void * __base, size_t __nmemb, size_t
__size, int(*_compar)(const void *, const void *));
int __attribute__((__cdecl__)) rand (void);
void * __attribute__((__cdecl__)) realloc (void * __r, size_t __size);
void __attribute__((__cdecl__)) srand (unsigned __seed);
double __attribute__((__cdecl__)) strtod (const char *__n, char **__end_PTR);
double __attribute__((__cdecl__)) _strtod_r (struct _reent *,const char *__n,
char **__end_PTR);
float __attribute__((__cdecl__)) strtof (const char *__n, char **__end_PTR);






long __attribute__((__cdecl__)) strtol (const char *__n, char **__end_PTR, int
__base);
long __attribute__((__cdecl__)) _strtol_r (struct _reent *,const char *__n,
char **__end_PTR, int __base);
unsigned long __attribute__((__cdecl__)) strtoul (const char *__n, char
**__end_PTR, int __base);
unsigned long __attribute__((__cdecl__)) _strtoul_r (struct _reent *,const char
*__n, char **__end_PTR, int __base);

int __attribute__((__cdecl__)) system (const char *__string);
# 183 "/usr/include/stdlib.h" 3 4
char * __attribute__((__cdecl__)) _dtoa_r (struct _reent *, double, int, int,
int *, int*, char**);







int __attribute__((__cdecl__)) _system_r (struct _reent *, const char *);

void __attribute__((__cdecl__)) __eprintf (const char *, const char *, unsigned
int, const char *);


# 5 "demo_counter.c" 2


static void demo_counter_destroy( demo_counter * self );
static int demo_counter_count( demo_counter * self, int count_amt );


demo_counter * demo_counter_constructor() {
 demo_counter * p_fresh = malloc( sizeof( demo_counter ) );

 if ( 0 != p_fresh ) {
  p_fresh->m_count = 0;
  p_fresh->destroy = demo_counter_destroy;
  p_fresh->count = demo_counter_count;
 }

 return p_fresh;
}


static void demo_counter_destroy( demo_counter * self ) {
 free( self );
}


static int demo_counter_count( demo_counter * self, int count_amt ) {
 self->m_count += count_amt;
 return self->m_count;
}


-- 
   Summary: not following "right-then-left" rule when compiling
function pointers
   Product: gcc
   Version: 4.3.2
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dj2con at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40627