Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Casing of Constants in the C1X Standard

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
6 posts • Page 1 of 1
Author
Message
wswartzendruber
Veteran
Veteran
User avatar
Posts: 1261
Joined: Tue Mar 23, 2004 1:16 am
Location: Idaho, USA

Casing of Constants in the C1X Standard

  • Quote

Post by wswartzendruber » Sat Nov 12, 2011 5:08 am

I'm looking at the current draft of the C1X standard. Here's an excerpt from the threading section:
The thrd_create function returns thrd_success on success, or thrd_nomem if no memory could be allocated for the thread requested, or thrd_error if the request could not be honored.
Why are these not uppercase?
Top
username234
Guru
Guru
Posts: 332
Joined: Wed May 09, 2007 3:35 pm

  • Quote

Post by username234 » Sat Nov 12, 2011 2:05 pm

The obvious answer is that thrd_success, thrd_nomem, and thrd_error are enum constants instead of macros, so to maintain consistency in the standard they shouldn't be capitalized. Now, why they're enum constants as opposed to macros, I can't say. Hopefully, they'll post a C1X Standard rationale that explains it.
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Top
wswartzendruber
Veteran
Veteran
User avatar
Posts: 1261
Joined: Tue Mar 23, 2004 1:16 am
Location: Idaho, USA

  • Quote

Post by wswartzendruber » Sat Nov 12, 2011 6:37 pm

I found this, but no explanation as to why. It seems that there are about two macros (uppercase) in the threading portion of C1X and about twenty enums.
Top
Hu
Administrator
Administrator
Posts: 24556
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Sat Nov 12, 2011 7:11 pm

I cannot speak for why they chose enums in this case, but the most common argument that I see in support of using enums is that macros are expanded by the preprocessor, which leads to less readable error messages if you misuse them, and that macros require extra work to make the values type safe. You usually want an error if you compare a foo_result to a bar_success, since foo and bar may have different numeric values for what constitutes "success." Using simple macros, those might be defined as integers, and the compiler would silently allow you to make a mistake. If you use an enum, you can do:

Code: Select all

enum class foo_result {
  success,
  fail1,
  fail2,
};

enum class bar_result {
  fail1,
  fail2,
  success,
};
Top
username234
Guru
Guru
Posts: 332
Joined: Wed May 09, 2007 3:35 pm

  • Quote

Post by username234 » Sat Nov 12, 2011 7:46 pm

That does remind me that you can do something like

Code: Select all

#include <stdlib.h>
#ifdef NULL
#undef NULL
#endif
#define NULL (void *)27
However, you can't do anything similar with enums. The one problem I have with this part of the C1X standard is that the functions have an integer return type. I would prefer to see something like

Code: Select all

enum thrd_return_cnsts {
    thrd_success,
    thrd_nomem,
    thrd_error };

enum thrd_return_cnsts thread_create(thrd_t *, thrd_start_t, void *);
But I don't really get a say in these things.
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Top
wswartzendruber
Veteran
Veteran
User avatar
Posts: 1261
Joined: Tue Mar 23, 2004 1:16 am
Location: Idaho, USA

  • Quote

Post by wswartzendruber » Sun Nov 13, 2011 7:00 am

Perhaps thread.h functions return different values depending on the underlying API (pthreads, etc...)?
Top
Post Reply

6 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Authors
Gentoo is a trademark of the Gentoo Foundation, Inc. and of Förderverein Gentoo e.V.
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-4.0 license.
The Gentoo Name and Logo Usage Guidelines apply.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy