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. Problem with #defined values

Problem with #defined values

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelpquestion
4 Posts 3 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.
  • L Offline
    L Offline
    ldsdbomber
    wrote on last edited by
    #1

    In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee

    L C C 3 Replies Last reply
    0
    • L ldsdbomber

      In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee

      L Offline
      L Offline
      ldsdbomber
      wrote on last edited by
      #2

      The answer of course is, yes, I was doing something incredibly stupid. I really ought to try the count to 10 rule before posting :-) unsurprisingly, sprintf_s( eBuff, 16, "%.0f", energyTable[ETABLESIZE*sel + NOMINDEX] ); works rather better, since energyTable is a float array DOH! sorry.....

      1 Reply Last reply
      0
      • L ldsdbomber

        In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        Could it be that your sel variable is 0 and you just didn't notice?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        1 Reply Last reply
        0
        • L ldsdbomber

          In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          It should work, indeed. That stated, why don't you use an enum for your symbols? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          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