Hello people !
I just subscripted to submit my question, but I'm not new to this forum. Actually I've been a regular visitor for the last weeks as I'm actively writing/debugging (my) C/C++ for my internship.
That being so, I come to you guys after having perused the threads of this forum coming up at my query, and ALL the Google results I found (... yeah there were four of them). I found parts of the answer I'm looking for, but I still can't debug my code for I don't understand the issue.
Here are the basics: I have a structure that contains basic types and a generic void* pointer. That pointer in my case points to a table of pointers to another structure (that contains pointers, but that's not the point (er...) here). I allocate the space for that table through a malloc(n*sizeof(void*)) instruction that to my understanding will perform the desired table the size of n times the size of a void* pointer. Anyways, if you followed that, here it is: I want to set all the pointers in that table, pointed to from my structure, to NULL values. Last, I do not know yet the type of the pointers in the table.
Here comes the code (to help...) :
And in the mainload.c file (but not in the main):
// said structure is in the header :
typedef struct rbn
/* the other members ... */
void * dat; // the pointer that will become a pointer to a table of void*
Upon compilation, I get a wonderful :
// 'ribbon' is the name of the pointer to my rbn structure
ribbon = malloc( sizeof(rbn) ); // memory allocation for the ribbon structure
ribbon->dat = malloc( n*sizeof(void*) ); // memory allocation for the table of pointers
// : initialization of the pointers in the dat table of pointers to NULL (table allocated just above)
for (i = 0; i < n; i++)
ribbon->dat[i] = NULL; // THE INSTRUCTION that protests (line 76)
// I also tried to write (ribbon->dat)[i] = NULL but to no avail
Really I don't get it. I thought that summing it up for this post was going to clarify and solve the problem, but I still don't get why I this is refused (gcc compiler under Linux SuZe distro).
mainload.c:76: warning: dereferencing 'void *' pointer
mainload.c:76: error: invalid use of void expression
I would understand if I couldn't increment a void* pointer, but gcc seems to have other bothers.
Well, there it is, 'plain and simple' ! I would greatly appreciate some help.
I leave it to your expert hands/eyes/minds to tell me what I am doing wrong.
[Edit]: Problem solved, see posts #4 and #6.