This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Prefix attributes vs. grammar


On Tue, 24 Jul 2001, Mark Mitchell wrote:

>   typedef void (__attribute__((__stdcall__))* pfn)();
> 
> This probably means that the pointed to function uses the `stdcall'
> calling convention.

This precise usage is supposed to be for MS-compatibility
<URL:http://gcc.gnu.org/ml/gcc-patches/1998-10/msg00641.html>:

	The Win32 folks have been agitating for a while to get support for

	  int (__attribute__ ((stdcall)) *f)();

	in the C++ compiler.

No-one has said exactly what the MS syntax and semantics are and whether
they agree or disagree with the documented GCC ones.  I couldn't locate
the formal specification of __stdcall etc. on msdn.microsoft.com though I
suppose it should be documented somewhere.

> It's a safe bet that nobody has any idea what
> this means in the presence of overload resolution, template
> instantiation, etc.

Start from the principle that the corresponding program without attributes
must be well-formed if the program with attributes is to be well-formed.  
(Where the corresponding program is mostly made by removing all
attributes, but in a few special cases something else may happen, e.g.
"int __attribute__((__mode__(__DI__))) x;" corresponding to "long long
x;".)  Given an example where problems arise, a listing of all relevant
paragraphs of ISO 14882 and an explanation of how they interact and how
attributes cause problems, I'll attempt to work out a plausible answer.

> The chances of implementing that correctly, not just in the
> parser but throughout the compiler, are nil.

> Note that this is still fully general in that you can always write:
> 
>   typedef void (*pfn) ();
>   typedef pfn __attribute__ ((__stdcall__)) stdcall_pfn;
> 
> So, we can still have whatever alleged semantics we had before.

Given the generality, restricting the syntax doesn't give any benefits
elsewhere in the compiler.

Given an understanding of the standard declarator syntax (i.e., having
memorised the relevant parts of the standard's syntax and description of
semantics), the meaning of attributes as part of nested declarators (as
opposed to prefix and postfix attributes on declarations) is natural and
obvious.  (Whereas the standard syntax itself may be confusing to those
who haven't memorised what the standard says.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]