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. signed value is out of range for enum constant

signed value is out of range for enum constant

Scheduled Pinned Locked Moved C / C++ / MFC
questionlinuxlearning
8 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:

    typedef enum {
    SOME_LINK =
    const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
    // <-- warning C4309: 'initializing' : truncation of constant value
    ....

    of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?

    L D CPalliniC 3 Replies Last reply
    0
    • _ _Flaviu

      I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:

      typedef enum {
      SOME_LINK =
      const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
      // <-- warning C4309: 'initializing' : truncation of constant value
      ....

      of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?

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

      Default enum is an int. You need a long.

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      _ 1 Reply Last reply
      0
      • L Lost User

        Default enum is an int. You need a long.

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        And how can setup that enum as ulong ?

        1 Reply Last reply
        0
        • _ _Flaviu

          I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:

          typedef enum {
          SOME_LINK =
          const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
          // <-- warning C4309: 'initializing' : truncation of constant value
          ....

          of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?

          D Offline
          D Offline
          Daniel Pfeffer
          wrote on last edited by
          #4

          A standard 'enum' in C can only be of types 'int' or 'unsigned int'. This value is an 'unsigned long long'. This sort of thing is usually done in order to aggregate constants into a namespace. Unfortunately, Standard C does not allow this. If your 'enum' is, for example, called LINKS, try:

          typedef unsigned long long LINKS;
          \#define SOME_LINK …

          Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

          1 Reply Last reply
          0
          • _ _Flaviu

            I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:

            typedef enum {
            SOME_LINK =
            const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
            // <-- warning C4309: 'initializing' : truncation of constant value
            ....

            of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?

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

            Quote:

            of course, I can disable this warning, but I want to do things right

            Do NOT disable the warning. Data would be truncated, (that is an error).

            In testa che avete, signor di Ceprano?

            _ 1 Reply Last reply
            0
            • CPalliniC CPallini

              Quote:

              of course, I can disable this warning, but I want to do things right

              Do NOT disable the warning. Data would be truncated, (that is an error).

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              Totally agree with you, that is why I asked here a solution. I have declared like this that enum:

              typedef enum LINK : unsigned long long {
              SOME_LINK = 0x01F5E4CA2A46E33ULL,
              ...

              and those warning has gone ... I hope is ok now.

              CPalliniC 1 Reply Last reply
              0
              • _ _Flaviu

                Totally agree with you, that is why I asked here a solution. I have declared like this that enum:

                typedef enum LINK : unsigned long long {
                SOME_LINK = 0x01F5E4CA2A46E33ULL,
                ...

                and those warning has gone ... I hope is ok now.

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

                So you are using C++ on a little endian machine, right?

                In testa che avete, signor di Ceprano?

                _ 1 Reply Last reply
                0
                • CPalliniC CPallini

                  So you are using C++ on a little endian machine, right?

                  _ Offline
                  _ Offline
                  _Flaviu
                  wrote on last edited by
                  #8

                  Yes, it is x86/x64 Intel. From Wikipedia: Current architectures The Intel x86 and also AMD64 / x86-64 series of processors use the little-endian format.

                  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