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. Array of Variables

Array of Variables

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelpquestionlounge
4 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.
  • G Offline
    G Offline
    Grahamfff
    wrote on last edited by
    #1

    I have been trying to store away an array of variables that I wish to display via a general display routine (i.e. deal with any type of variable). e.g. typedef struct { void* data [10][20][20]; DATA_DETAILS dataDetails[10][20][20]; short feildsInDisplay [10][20]; }DISPLAY_DB; DISPLAY_DB myDB; // Store away the addresses of the display data items myDB.feildsInDisplay[0][0] = 2; myDB.data[0][0][0] = &(shortInteger1); myDB.dataDetails[0][0][0] = short_integer_details; myDB.data[0][0][1] = &(float_data_item); . etc At some point later in the program // Now get the data for display dataStr.Format ("%d", myDB.data[0][0][0]) ; strName = myDB.dataDetails[0][0][0].fieldDesc; m_cEditTest.SetWindowText (strName + dataStr); What I get is the correct dataDetails but the address of the data not the data itself. How do I dereference this data. e.g. Test Data 1 = 438181 and not Test Data 1 = 1234 If I try dataStr.Format ("%d", *myDB.data[0][0][0]);I get an illegal indirection error. Also I cannot store away the address of bit fields I get the following errors c:\Export_LibDlg.cpp(479): error C2104: '&' on bit field ignored c:\Export_LibDlg.cpp(549): error C2100: illegal indirection where the data is unsigned dataBit : 4; myDB.data[0][0][0] = &(dataBit); Any suggestions, grahamfff

    T M R 3 Replies Last reply
    0
    • G Grahamfff

      I have been trying to store away an array of variables that I wish to display via a general display routine (i.e. deal with any type of variable). e.g. typedef struct { void* data [10][20][20]; DATA_DETAILS dataDetails[10][20][20]; short feildsInDisplay [10][20]; }DISPLAY_DB; DISPLAY_DB myDB; // Store away the addresses of the display data items myDB.feildsInDisplay[0][0] = 2; myDB.data[0][0][0] = &(shortInteger1); myDB.dataDetails[0][0][0] = short_integer_details; myDB.data[0][0][1] = &(float_data_item); . etc At some point later in the program // Now get the data for display dataStr.Format ("%d", myDB.data[0][0][0]) ; strName = myDB.dataDetails[0][0][0].fieldDesc; m_cEditTest.SetWindowText (strName + dataStr); What I get is the correct dataDetails but the address of the data not the data itself. How do I dereference this data. e.g. Test Data 1 = 438181 and not Test Data 1 = 1234 If I try dataStr.Format ("%d", *myDB.data[0][0][0]);I get an illegal indirection error. Also I cannot store away the address of bit fields I get the following errors c:\Export_LibDlg.cpp(479): error C2104: '&' on bit field ignored c:\Export_LibDlg.cpp(549): error C2100: illegal indirection where the data is unsigned dataBit : 4; myDB.data[0][0][0] = &(dataBit); Any suggestions, grahamfff

      T Offline
      T Offline
      tlerner
      wrote on last edited by
      #2

      myDB.data[0][0][0] is a void* so if you say *myDB.data[0][0][0] you should get an illegal indirection. Try (int*)myDB.data[0][0][0] in your format. Could be wrong.

      1 Reply Last reply
      0
      • G Grahamfff

        I have been trying to store away an array of variables that I wish to display via a general display routine (i.e. deal with any type of variable). e.g. typedef struct { void* data [10][20][20]; DATA_DETAILS dataDetails[10][20][20]; short feildsInDisplay [10][20]; }DISPLAY_DB; DISPLAY_DB myDB; // Store away the addresses of the display data items myDB.feildsInDisplay[0][0] = 2; myDB.data[0][0][0] = &(shortInteger1); myDB.dataDetails[0][0][0] = short_integer_details; myDB.data[0][0][1] = &(float_data_item); . etc At some point later in the program // Now get the data for display dataStr.Format ("%d", myDB.data[0][0][0]) ; strName = myDB.dataDetails[0][0][0].fieldDesc; m_cEditTest.SetWindowText (strName + dataStr); What I get is the correct dataDetails but the address of the data not the data itself. How do I dereference this data. e.g. Test Data 1 = 438181 and not Test Data 1 = 1234 If I try dataStr.Format ("%d", *myDB.data[0][0][0]);I get an illegal indirection error. Also I cannot store away the address of bit fields I get the following errors c:\Export_LibDlg.cpp(479): error C2104: '&' on bit field ignored c:\Export_LibDlg.cpp(549): error C2100: illegal indirection where the data is unsigned dataBit : 4; myDB.data[0][0][0] = &(dataBit); Any suggestions, grahamfff

        M Offline
        M Offline
        mahade1
        wrote on last edited by
        #3

        Actually, if u r setting myDB.data[0][0][0] to a short integer (as the name says), then it would be wiser to use (short int *)myDB.data[0][0][0] in your format.

        1 Reply Last reply
        0
        • G Grahamfff

          I have been trying to store away an array of variables that I wish to display via a general display routine (i.e. deal with any type of variable). e.g. typedef struct { void* data [10][20][20]; DATA_DETAILS dataDetails[10][20][20]; short feildsInDisplay [10][20]; }DISPLAY_DB; DISPLAY_DB myDB; // Store away the addresses of the display data items myDB.feildsInDisplay[0][0] = 2; myDB.data[0][0][0] = &(shortInteger1); myDB.dataDetails[0][0][0] = short_integer_details; myDB.data[0][0][1] = &(float_data_item); . etc At some point later in the program // Now get the data for display dataStr.Format ("%d", myDB.data[0][0][0]) ; strName = myDB.dataDetails[0][0][0].fieldDesc; m_cEditTest.SetWindowText (strName + dataStr); What I get is the correct dataDetails but the address of the data not the data itself. How do I dereference this data. e.g. Test Data 1 = 438181 and not Test Data 1 = 1234 If I try dataStr.Format ("%d", *myDB.data[0][0][0]);I get an illegal indirection error. Also I cannot store away the address of bit fields I get the following errors c:\Export_LibDlg.cpp(479): error C2104: '&' on bit field ignored c:\Export_LibDlg.cpp(549): error C2100: illegal indirection where the data is unsigned dataBit : 4; myDB.data[0][0][0] = &(dataBit); Any suggestions, grahamfff

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          Grahamfff wrote: Also I cannot store away the address of bit fields That's correct. This is prohibited by the C standard. This is simply because if the field starts part-way through a byte, there is no way the compiler can take its address - it has to be on a byte boundary.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          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