char pointer to 2D char array 
Author Message
 char pointer to 2D char array

Hello, everyone!

Could someone please tell me if this declaration is OK:

char entry_string[4][255];
char *entry[4] =
{entry_string[0], entry_string[1], entry_string[2], entry_string[3]};

Splint warns me about this:

phoebe_gui_accessories.c:500:20: Initialized storage entry_string[0] not
completely defined (*(entry_string[0]) is undefined):
    entry[0] = entry_string[0]
  Storage derivable from a parameter, return value or global is not

need not be defined.  (Use -compdef to inhibit warning)

And alike for the [1], [2] and [3]. Is it true that I cannot do it this
way? I use sprintf later to write to these pointers, e.g.

sprintf (entry[0], "String1");

etc.

Thanks for your time,

Andrej



Sun, 09 Jan 2005 18:57:48 GMT  
 char pointer to 2D char array

Quote:
> Hello, everyone!

> Could someone please tell me if this declaration is OK:

> char entry_string[4][255];
> char *entry[4] =
> {entry_string[0], entry_string[1], entry_string[2], entry_string[3]};

In the absense of any other context, I'd say this was fine.

--
Peter



Sun, 09 Jan 2005 19:53:45 GMT  
 char pointer to 2D char array

Quote:

> Hello, everyone!

> Could someone please tell me if this declaration is OK:

> char entry_string[4][255];
> char *entry[4] =
> {entry_string[0], entry_string[1], entry_string[2], entry_string[3]};

> Splint warns me about this:

> phoebe_gui_accessories.c:500:20: Initialized storage entry_string[0] not
> completely defined (*(entry_string[0]) is undefined):
>     entry[0] = entry_string[0]
>   Storage derivable from a parameter, return value or global is not

> need not be defined.  (Use -compdef to inhibit warning)

Splint is being an idiot. The contents of entry_string[0] have nothing
whatever to do with initialising a char * to point to it.
You may or may not be able to get around this using &entrystring[0][0],
but frankly I doubt it.

Richard



Sun, 09 Jan 2005 20:46:33 GMT  
 char pointer to 2D char array

Quote:

> Hello, everyone!

> Could someone please tell me if this declaration is OK:

> char entry_string[4][255];
> char *entry[4] =
> {entry_string[0], entry_string[1], entry_string[2], entry_string[3]};

> Splint warns me about this:

> phoebe_gui_accessories.c:500:20:
> Initialized storage entry_string[0] not
> completely defined (*(entry_string[0]) is undefined):
>     entry[0] = entry_string[0]
>   Storage derivable from a parameter, return value or global is not

> need not be defined.  (Use -compdef to inhibit warning)

> And alike for the [1], [2] and [3].
> Is it true that I cannot do it this way?

If entry_string is static or global,
then you can do it this way.

--
 pete



Sun, 09 Jan 2005 20:50:57 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. A char pointer (char *) vs. char array question

2. arrays and pointers, char * vs. char [], distinction

3. Converting char array of literals chars to escape chars

4. Differences between char array[SIZE] and char *array

5. Comparison with pointer to pointer to char, and char

6. 2D array of pointers to 2D arrays

7. 2d arrays... (of char)

8. Char* array to Unsigned Char*

9. char* to char array[] ?

10. char arrays versus char strings.

11. Passing a char array[n] to a function expecting a char*

12. Reg.allocating memory for double char pointer(char ** buf)

 

 
Powered by phpBB® Forum Software