Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:43:25+00:00 2026-05-26T09:43:25+00:00

OK, this is related to question Constants in Objective C . I created Constants.h

  • 0

OK, this is related to question “Constants in Objective C”.

I created Constants.h and its corresponding Constants.m file:

// Constants.h
extern int const BOOKS; 
typedef enum SSDifficultyLevel {
    EASY = 0,
    MEDIUM = 1,
    HARD = 2
} SSDifficultyLevel;

// Constants.m
int const BOOKS = 66;

My question: Is OK for the enum to be typedef‘d in Constants.h? The code is compiling fine (no warnings or errors so far) but I was wondering if this is the right way to do it, as the solution provided in the related question involves splitting the constant’s definition and declaration.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:43:26+00:00Added an answer on May 26, 2026 at 9:43 am

    well, a constant and an enum serve different purposes (although there is some obvious overlap). so, just don’t go too far from what people would expect, unless you have a really good reason to break that rule.

    personally, i don’t like the “global constants header” much, as you should usually associate those declarations with what they are used with. for example, Apple’s frameworks typically declare the enums near the interfaces they relate to, and the notification names in the same header as the class.

    other than that, you have declared things correctly.

    if you use c++ or objc++, then you will want to fix that extern because the names may differ, and that can result in link errors.

    something like this should do the trick:

    #if defined(__cplusplus)
    #define MONExternC extern "C"
    #else
    #define MONExternC extern
    #endif
    

    then you would declare BOOKS like so:

    MONExternC int const BOOKS; 
    

    one other note, and this may have been only for illustration in your example: those identifiers are very short, and can easily cause collisions with other identifiers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is related to this thread. Here is the code #include <stdio.h> int
The answers to this related question of mine lead me to choose Java for
I found this related question: How do I use composition with inheritance? I would
This is a related question to one I posted earlier... I'm trying to sum
This is a related question to: Android NFC start service In Android, can an
This is a related question to one I posted earlier today, I was initially
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
I hope this is programmer-related question. I'm in the hobby business of C# programming.
Important : Please see this very much related question: Return multiple values in C++
This is related to a question I asked the other day on how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.