Connecting Tech Pros Worldwide Forums | Help | Site Map

Why this typedef is wrong?

linq936@hotmail.com
Guest
 
Posts: n/a
#1: Jun 18 '07
Hi,
I have a typedef like this,

typedef (char* [20]) arrp;

I want to define a type which is an array, the array has 20 elements
each of which is a char*.

I get compile error:

syntax error before "char"

Here is the full code:

typedef (char* [20]) arrp;

int main(){
arrp a;

return 0;
}


Do you see what is wrong?


Richard Heathfield
Guest
 
Posts: n/a
#2: Jun 18 '07

re: Why this typedef is wrong?


linq936@hotmail.com said:
Quote:
Hi,
I have a typedef like this,
>
typedef (char* [20]) arrp;
Whoa, stop right there! To define a type-synonym properly, start off by
pretending you're trying to create an object:

char *arrp[20];

NOW put typedef on the front.

typedef char *arrp[20];

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Barry Schwarz
Guest
 
Posts: n/a
#3: Jun 18 '07

re: Why this typedef is wrong?


On Sun, 17 Jun 2007 20:41:29 -0700, linq936@hotmail.com wrote:
Quote:
>Hi,
I have a typedef like this,
>
>typedef (char* [20]) arrp;
How would you define an object that is an array of 20 char? How would
you define another object that is an array of 20 pointers to char? The
typedef to declare the alias for a type follows the exact same syntax
with "typedef" prepended in front.
Quote:
>
I want to define a type which is an array, the array has 20 elements
>each of which is a char*.
>
I get compile error:
>
syntax error before "char"
>
Here is the full code:
>
>typedef (char* [20]) arrp;
>
>int main(){
arrp a;
Others will argue that a typedef is unnecessary for such a simple
type. Unless you are doing something special, they are usually
correct.
Quote:
>
return 0;
>}

Remove del for email
Closed Thread