Delete element of array of structures, including excess memory.

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 655 Views - Last Post: 10 July 2013 - 07:39 PM Rate Topic: -----

#16 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: Delete element of array of structures, including excess memory.

Posted 10 July 2013 - 03:24 PM

Its this line

Example = (EXAMPLE *)realloc(Example, sizeof(EXAMPLE) * (*size));

Thats the problem

you have sizeof(Example)

Snoopy
Was This Post Helpful? 2
  • +
  • -

#17 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3449
  • View blog
  • Posts: 10,643
  • Joined: 05-May 12

Re: Delete element of array of structures, including excess memory.

Posted 10 July 2013 - 03:25 PM

MSVC defaults to 32-bit builds unless you take other steps. So sizeof(Example) == 4 because pointers are only 32 bits wide. If building for 64 bits, the sizeof(Example) == 8 which interestingly corresponds to sizeof(struct EXAMPLE);
Was This Post Helpful? 2
  • +
  • -

#18 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: Delete element of array of structures, including excess memory.

Posted 10 July 2013 - 03:27 PM

Ahh,

interesting Mr Skydiver...

+1

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#19 Hero26  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 13

Re: Delete element of array of structures, including excess memory.

Posted 10 July 2013 - 05:24 PM

View Postsnoopy11, on 10 July 2013 - 03:24 PM, said:

Its this line

Example = (EXAMPLE *)realloc(Example, sizeof(EXAMPLE) * (*size));

Thats the problem

you have sizeof(Example)

Snoopy


Yes that's it! I de-referenced Example and it worked. I've been really struggling with this so thanks for helping me get to the bottom of it. In theory it should work in my main program now.
It's always the smallest thing that gets missed isn't it.
Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is offline

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: Delete element of array of structures, including excess memory.

Posted 10 July 2013 - 07:39 PM

One of your problems is that you need to move the structure definition to before your function prototypes.

Quote

/main.c|7|error: array type has incomplete element type|
/main.c|7|warning: ‘struct EXAMPLE’ declared inside parameter list [enabled by default]|
/main.c|7|warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]|
/main.c|8|error: array type has incomplete element type|
/main.c|8|warning: ‘struct EXAMPLE’ declared inside parameter list [enabled by default]|
/main.c|9|error: array type has incomplete element type|
/main.c||In function ‘main’:|
/main.c|26|error: type of formal parameter 1 is incomplete|
/main.c|27|error: type of formal parameter 1 is incomplete|
/main.c|29|error: type of formal parameter 1 is incomplete|
/main.c|30|error: type of formal parameter 1 is incomplete|
/main.c|26|confused by earlier errors, bailing out|
||=== Build finished: 8 errors, 3 warnings (0 minutes, 0 seconds) ===|


Jim
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2