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. unknown size of void *

unknown size of void *

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
5 Posts 5 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
    liquid_
    wrote on last edited by
    #1

    What is the reason of error message: error C2036: 'void *' : unknown size This was a result of compilation of such a code snippet:

    void ** c=malloc(20);
    int i=1;

    c[i] = c[i-1]+1;

    (Forget uninitialized block of memory c) I'd expect that size of any pointer is known.

    C A T _ 4 Replies Last reply
    0
    • L liquid_

      What is the reason of error message: error C2036: 'void *' : unknown size This was a result of compilation of such a code snippet:

      void ** c=malloc(20);
      int i=1;

      c[i] = c[i-1]+1;

      (Forget uninitialized block of memory c) I'd expect that size of any pointer is known.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      The pointer points to something which is not known (otherwise, you would have used int* for instance). Thus, when you are accessing it as an array, the compiler doesn't know how much offset he has to apply to the address to access the following element (because he doesn't know the size of an element). If you want to manipulate bytes, I suggest that you use an array of unsigned char instead.

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • L liquid_

        What is the reason of error message: error C2036: 'void *' : unknown size This was a result of compilation of such a code snippet:

        void ** c=malloc(20);
        int i=1;

        c[i] = c[i-1]+1;

        (Forget uninitialized block of memory c) I'd expect that size of any pointer is known.

        A Offline
        A Offline
        Adam Roderick J
        wrote on last edited by
        #3

        I dont think it is a good practice to allocate a viod pointer. Void pointer is not introduded so as to allocate and use, rather its use is in holding data. Since Void can hold any type of data. You cannot able to allocate the exact length. Thats why complier doesnot allow you to do so. So it better to allocate for some data types. :)

        1 Reply Last reply
        0
        • L liquid_

          What is the reason of error message: error C2036: 'void *' : unknown size This was a result of compilation of such a code snippet:

          void ** c=malloc(20);
          int i=1;

          c[i] = c[i-1]+1;

          (Forget uninitialized block of memory c) I'd expect that size of any pointer is known.

          T Offline
          T Offline
          TheGreatAndPowerfulOz
          wrote on last edited by
          #4

          c[i-1] is a void * c[i-1] + 1 you're trying to increment to the next "void" object, but void has no size change the line of code

          void** c = malloc(20)

          to

          int** c = malloc(20)

          and you'll see that it compiles.

          1 Reply Last reply
          0
          • L liquid_

            What is the reason of error message: error C2036: 'void *' : unknown size This was a result of compilation of such a code snippet:

            void ** c=malloc(20);
            int i=1;

            c[i] = c[i-1]+1;

            (Forget uninitialized block of memory c) I'd expect that size of any pointer is known.

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            liquid_ wrote:

            I'd expect that size of any pointer is known.

            This is true. Size of a pointer is 32 bits in 32-bit Windows and 64 bits in 64-bit Windows. But the error talks about something else. Consider this example. int* i = 10; This uses 4 bytes to store the value 10 char* c = 10; This uses 1 byte to store the value 10 This is what the above error talks about. So if you do void* v = 10; you should get this error since the compiler is not able to get the size needed.

            «_Superman_» I love work. It gives me something to do between weekends.

            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