List:Internals« Previous MessageNext Message »
From:Mats Kindahl Date:June 25 2009 9:12am
Subject:Re: MySql coding style: Request for deprecation of UPPERCASE typedefs
View as plain text  

Michael Widenius wrote:
> 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?

Sorry, I confused two situations: this will not produce an error. The real
problem is the following:

In some places of the code, it is "typedef struct st_foo FOO" and in some places
it is "struct FOO" and you always have to check which one it is when forward
declaring the name, which is wasting time (I'm sitting with this right now, and
it is not always as easy as hitting M-.).

- If it is "typedef struct st_foo FOO", "struct FOO" will throw an error.

- If it is "struct FOO", then "typedef struct st_foo FOO" will throw 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.

I think that in practice it is not possible to move from C++ to C (since C++
code inevitable will contain C++ constructs), and that the extra work required
to move from C to C++ does not really motivate using typedefs.

> As MySQL is using C libraries with typedefs, you can't easily get rid
> of all the typedefs.

It depends on your definition of easy, but I think I can with only minor changes
to the C code...

Just my few cents,
Mats Kindahl
-- 
Mats Kindahl
Senior Software Engineer
Database Technology Group
Sun Microsystems
Thread
MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen22 Jun
  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl22 Jun
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius24 Jun
      • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen25 Jun
        • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
      • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl25 Jun
        • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
          • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsJay Pipes27 Jun
          • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen29 Jun
          • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl29 Jun
            • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKristian Nielsen29 Jun
              • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen30 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl30 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKristian Nielsen30 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen1 Jul
                    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKristian Nielsen1 Jul
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKonstantin Osipov1 Jul
              • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKonstantin Osipov1 Jul
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKristian Nielsen2 Jul
  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKonstantin Osipov22 Jun
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsRoy Lyseng22 Jun
      • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen23 Jun
        • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl23 Jun
          • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen23 Jun
            • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl23 Jun
              • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl30 Jun
            • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius24 Jun
              • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen25 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsJonas Oreland25 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsDavi Arnaut25 Jun
                    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsJay Pipes25 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl25 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl30 Jun
              • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMats Kindahl25 Jun
                • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius27 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsJay Pipes27 Jun
                    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius30 Jun
                  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsJay Pipes27 Jun
                    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsMichael Widenius1 Jul
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen23 Jun
  • Re: MySql coding style: Request for deprecation of UPPERCASEtypedefsSergei Golubchik22 Jun
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen23 Jun
      • Re: MySql coding style: Request for deprecation of UPPERCASEtypedefsSergei Golubchik23 Jun
        • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen23 Jun
  • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsAlex Esterkin1 Jul
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsTor Didriksen1 Jul
    • Re: MySql coding style: Request for deprecation of UPPERCASE typedefsKonstantin Osipov1 Jul