AFAIK a typedef just defines an alias for an existing type, it does not matter how the type is defined. This is why putting the typedef before the enum declaration is illegal, as the enum isn't yet a type in scope.
Although mbed, Keil RV and Visual Studio 2010 all compile it without error I'm pretty certain they're not conforming to the standard here. GCC (4.5.1) produces two errors for the typedef:
error: use of enum ‘PinMode’ without previous declaration
error: invalid type in declaration before ‘;’ token
which are understandable after I found out about the scoping rule for typedefs.
I guess the compilers that don't complain are using file scope instead of lexical scope.
Hi,
While experimenting with offline compilers (I miss easy refactoring) I ran into compilation issues with the mbed header files, in particular the approach of defining a typedef before the corresponding enum, e.g from PinNames.h.
AFAIK this is not legal C++ as the typedef is forward referencing the enum.