Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

GCC attributes

<< < (2/6) > >>

rickg22:
It's interesting to see how different people think differently (doh). Thomas has an obsession with optimizing the implementations (i.e. blockallocator), while i have an obsession with optimizing the algorithms. I think we make a good combination :)

takeshimiya:
Urxae is right, never define something starting with an _ (underscore) or __ (double underscore), because those are reserved for usage by the implemetator of the standard library, so it's probable to have name clashes.

As Stroustrup says also, having macros in UPPERCASE helps. Appart, as they are a little more hard to read, you try to not use them whenever possible.

Also, wxWidgets have interesting macros in defs.h, and IMHO you should use them whenever possible (don't reinvent the well :)) like:

/*  Macro to issue warning when using deprecated functions with gcc3 or MSVC7: */
#if wxCHECK_GCC_VERSION(3, 1)
    #define wxDEPRECATED(x) x __attribute__ ((deprecated))
#elif defined(__VISUALC__) && (__VISUALC__ >= 1300)
    #define wxDEPRECATED(x) __declspec(deprecated) x
#else
    #define wxDEPRECATED(x) x
#endif

So, if you are about to introduce a new macro that it's not defined in wxWidgets, a good name would be something as cbUNLIKELY.

thomas:
Thanks, I knew about these, but I don't like their syntax (putting everything into a macro argument), and they only define a few attributes. For example, you cannot write int someFunction() wxDEPRECATED; which is a lot better to read.

Also, wxWidgets is notorious about defining really sick macros (#define new) and using attributes incorrectly. Have you ever wondered why wxWidgets produces about 100.000 warnings during a normal compile? Most of them are related to incorrectly used attributes.

takeshimiya:

--- Quote from: thomas on December 17, 2005, 01:48:19 am ---Also, wxWidgets is notorious about defining really sick macros (#define new) and using attributes incorrectly.

--- End quote ---
First, it can be disabled with wxUSE_GLOBAL_MEMORY_OPERATORS.
Second, they must have a reason for doing that.
Third, if you are complaining about that, why don't send a feature request or patch?
Four, if you know things that you think are wrong in wxWidgets itself, and can do nothing about it, could you make a separate thread (or @WiKi) indicating things to "avoid" in wxWidgets, so other users can benefit from that.

Now back on topic:
Saying that wxDEPRECATED(x) is harder to read is an opinion. In my view, is better because: it's capitalized, and it notes that the entire macro is applied.
However all of thatisn't that important compared to this:

While your someFunction() cbDEPRECATED works on GCC, it doesn't work on Visual C, because the declaration is inverted cbDEPRECATED someFunction().

So, putting everything into a macro argument like wxDEPRECATED(x) is the only solution.
You said "I knew about these", but it seems you didn't read what the wx #define does and how it does.

I hope you'll understand.

Urxae:

--- Quote from: Takeshi Miya on December 17, 2005, 01:22:29 am ---Urxae is right, never define something starting with an _ (underscore) or __ (double underscore), because those are reserved for usage by the implemetator of the standard library, so it's probable to have name clashes.

--- End quote ---

While true, the complete rules are a bit more complex:

In C, the implementation reserves

* any global-scope name beginning with _
* any name beginning with _ followed by an upper-case letter
* any name beginning with __C++ additionally reserves any name containing __ anywhere in it, not just at the beginning.

Also, "the implementation" covers both the standard library and the compiler itself.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version