By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

Why this typedef is wrong?

P: n/a
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?

Jun 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
li*****@hotmail.com said:
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.
Jun 18 '07 #2

P: n/a
On Sun, 17 Jun 2007 20:41:29 -0700, li*****@hotmail.com wrote:
>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.
>
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.
>
return 0;
}

Remove del for email
Jun 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.