Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Possible to #if in case an enum exists?

Possible to #if in case an enum exists?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arnold_w
    wrote on last edited by
    #1

    Is it possible to somehow check during compile time if an enum exists, i.e. something like this:

    typedef enum {
    MY_ENUM_VALUE = 0
    } myEnum_e;

    #define DOES_ENUM_EXIT(__ARG__) ??? What goes here???

    if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
    }

    I know that I could achieve something similar easily be using

    #define MY_ENUM_VALUE (0)

    instead, but then my code wouldn't be type safe.

    CPalliniC L 2 Replies Last reply
    0
    • A arnold_w

      Is it possible to somehow check during compile time if an enum exists, i.e. something like this:

      typedef enum {
      MY_ENUM_VALUE = 0
      } myEnum_e;

      #define DOES_ENUM_EXIT(__ARG__) ??? What goes here???

      if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
      }

      I know that I could achieve something similar easily be using

      #define MY_ENUM_VALUE (0)

      instead, but then my code wouldn't be type safe.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Nope (AFAIK), see Conditional inclusion - cppreference.com[^].

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • A arnold_w

        Is it possible to somehow check during compile time if an enum exists, i.e. something like this:

        typedef enum {
        MY_ENUM_VALUE = 0
        } myEnum_e;

        #define DOES_ENUM_EXIT(__ARG__) ??? What goes here???

        if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
        }

        I know that I could achieve something similar easily be using

        #define MY_ENUM_VALUE (0)

        instead, but then my code wouldn't be type safe.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        No, because the #define statement is handled by the preprocessor, and the enum value is not known until it is fed into the compiler, which comes later.

        Greg UtasG 1 Reply Last reply
        0
        • L Lost User

          No, because the #define statement is handled by the preprocessor, and the enum value is not known until it is fed into the compiler, which comes later.

          Greg UtasG Offline
          Greg UtasG Offline
          Greg Utas
          wrote on last edited by
          #4

          Robust Services Core | Software Techniques for Lemmings | Articles

          <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
          <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

          L 1 Reply Last reply
          0
          • Greg UtasG Greg Utas

            Robust Services Core | Software Techniques for Lemmings | Articles

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            :thumbsup:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups