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 7856395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:41:37+00:00 2026-06-02T20:41:37+00:00

Suppose there is a C++11 API that uses enum classes: // api.hpp enum class

  • 0

Suppose there is a C++11 API that uses enum classes:

// api.hpp
enum class E {A, B, C};
void f(E);
...

// api.cpp
void f(E e)
{
    if (e == E::A)
       ...
}

Now suppose I would like to use this API, but I don’t have a C++11 compiler. So I:

  • Modify api.hpp and change the enum class to be just a regular enum.
  • Write some code code that includes the modified api.hpp and uses the API normally (e.g. calls f).
  • Compile this code with my non-C++11 compiler and link it to the API implementation which was compiled with a C++11 compiler (using the unmodified api.hpp).

This seems to work with GCC, but is it safe in general, or am I playing with fire (ODR violations and such)?

Assume the two compilers are otherwise link-compatible, it is only the enum vs. enum class that is at issue.

  • 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-06-02T20:41:40+00:00Added an answer on June 2, 2026 at 8:41 pm

    Like ildjarn is saying, this is undefined behavior. And the reason that this actually can fail on real implementations is that normal C++03 enums don’t have a fixed underlying type. While your enum-class type always has “int” as its underlying type, a corresponding C++03 enum could have “short” as its underlying type, making the code not be layout compatible.

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

Sidebar

Related Questions

Suppose there's a top-secret list (inherits its permissions from its parent) that contains records
Suppose I have class like this (simplified): class Foo_p; class Foo { private: Foo_p
I am developing sample application that uses Google Map API. I have generated Google
Suppose I need to call an RPC HTTP api that requires the client to
Suppose I have a library that uses exceptions to indicate success or failure. I
Let's suppose I write public API in C#: public void Method(object param) { if(param
Suppose you have an API you've written that collects data in real time in
I have a JAR file that contains an API that uses external model files.
Suppose we have classes Gallery and Image. There can be many images in one
In Delphi 2009 and Windows API, is there a way to detect that a

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.