Hi!
>>>>> "Mats" == Mats Kindahl <Mats.Kindahl@stripped> writes:
Mats> Tor Didriksen wrote:
>> hi
>>
>> "Structure types are typedef'ed to an all-upper-case identifier."
>> Can someone explain the reasoning behind this?
>> ALL_UPPERCASE_NAME says DANGEROUS_THIS_IS_A_MACRO to me, rather than
>> struct/class.
>>
>> typedef struct foo { ... } FOO;
>> Is legacy C-style, and does not belong in a C++ style guide (imho).
Mats> I agree.
Mats> In addition, it is a problem because there cannot be multiple typedefs, but
Mats> there can be multiple forward declarations, which makes it very difficult to do
Mats> a forward declaration of a structure using, e.g.:
Mats> typedef struct foo FOO;
Mats> In the event that the header file is included by some other file that does a
Mats> similar forward declaration, the compiler will throw an error.
We have already solved this in many places of MySQL / mysys by using struct
foo for cases where the typedef is not yet done so I wouldn't call
this a notable problem.
I also tested this with gcc and didn't get any error for the
following file:
typedef struct foo FOO;
struct foo {int a;};
typedef struct foo FOO;
struct foo a;
FOO b;
What is it that would give an error?
Mats> I would prefer if we never used typedef to introduce aliases for
Mats> struct/class/union, they cause more problem that it's worth, and they are not
Mats> needed in C++ at all.
MySQL was coded in part so that it would be able to easily mix C++ and
C code and allow you to move things from C++ and C with little work.
As MySQL is using C libraries with typedefs, you can't easily get rid
of all the typedefs.
Regards,
Monty