| View previous topic :: View next topic |
| Author |
Message |
Andrew Chalk Guest
|
Posted: Mon Sep 15, 2003 9:49 am Post subject: typedef decalrations |
|
|
I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
Thanks!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Russell Hanneken Guest
|
Posted: Mon Sep 15, 2003 3:39 pm Post subject: Re: typedef decalrations |
|
|
"Andrew Chalk" <achalk (AT) XXXmagnacartasoftware (DOT) com> wrote
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
You can, but you have to write it like this:
typedef char D2[1400];
Regards,
Russell Hanneken
[email]rhanneken (AT) pobox (DOT) com[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Attila Feher Guest
|
Posted: Mon Sep 15, 2003 3:39 pm Post subject: Re: typedef decalrations |
|
|
Andrew Chalk wrote:
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
You can:
typedef char D2[1400];
Just like a variable declaration.
--
Attila aka WW
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ivan Vecerina Guest
|
Posted: Mon Sep 15, 2003 3:44 pm Post subject: Re: typedef decalrations |
|
|
"Andrew Chalk" <achalk (AT) XXXmagnacartasoftware (DOT) com> wrote
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
You can, but you have to write it as follows:
typedef char D2[1400];
Remember that the expression that follows typedef should
always follow the same syntax as a variable declaration.
hth
--
http://ivan.vecerina.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Mon Sep 15, 2003 3:46 pm Post subject: Re: typedef decalrations |
|
|
"Andrew Chalk" <achalk (AT) XXXmagnacartasoftware (DOT) com> writes:
| Quote: | why can't I:
typedef char[1400] D2;
|
try
typedef char D2[1400];
--
Gabriel Dos Reis <gdr (AT) integrable-solutions (DOT) net>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Mon Sep 15, 2003 9:54 pm Post subject: Re: typedef decalrations |
|
|
In article <sC99b.297$xE5.482344098 (AT) newssvr12 (DOT) news.prodigy.com>,
Andrew Chalk wrote:
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
That isn't normal declarator syntax. You wouldn't declare an
object D2 as:
char[1400] D2;
but instead as:
char D2[1400];
With minor exceptions, typedef statements use the same
declarator syntax as object and function declarations, so you
should write:
typedef char D2[1400];
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Dhruv Guest
|
Posted: Mon Sep 15, 2003 9:54 pm Post subject: Re: typedef decalrations |
|
|
On Mon, 15 Sep 2003 05:49:01 -0400, Andrew Chalk wrote:
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
It can, just place the array thing after D2. So, it would change to
something like:
typedef char D2[1400];
Would make D2 an array of 1400 chars, so using it like this would mean
using an array of chars.
D2 DObj;
Be careful of 1 thing though. If you use new to create a new D2 object,
be sure to delete[] it, and not delete it.
Regards,
-Dhruv.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Marco Manfredini Guest
|
Posted: Mon Sep 15, 2003 10:02 pm Post subject: Re: typedef decalrations |
|
|
Andrew Chalk wrote:
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
|
try:
typedef char D2[14000];
Syntactically, a typedef works like a variable declaration, only that
you are declaring a type instead a variable.
Marco
--
The text above is a result of a bug in my newsreader and I take no
responsibility for this text appearing in my post.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Dan McLeran Guest
|
Posted: Tue Sep 16, 2003 6:36 am Post subject: Re: typedef decalrations |
|
|
| Quote: | I can:
typedef char D1;
why can't I:
typedef char[1400] D2;
I.e. declare a typedef corresponding to 1400 bytes.
Thanks!
|
D2 doesn't make much sense. What you're doing is creating an alias for
a type, not assigning a size, i.e. you would write:
char buffer[1400], not char[1400] buffer.
What you can do is something like this:
template<unsigned size>
struct wrapper
{
char buffer[size];
};
typedef wrapper<1400> t2;
int main()
{
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Tue Sep 16, 2003 1:17 pm Post subject: Re: typedef decalrations |
|
|
In article <19b0e504.0309151302.67b3b580 (AT) posting (DOT) google.com>, Dan
McLeran <dan.r.mcleran (AT) seagate (DOT) com> writes
| Quote: | D2 doesn't make much sense. What you're doing is creating an alias for
a type, not assigning a size, i.e. you would write:
char buffer[1400], not char[1400] buffer.
What you can do is something like this:
template<unsigned size
struct wrapper
{
char buffer[size];
};
typedef wrapper<1400> t2;
int main()
{
return 0;
}
But why not use the simple answer of writing the original declaration |
correctly:
typedef char D2[1400];
? There is no point in reaching for a Swiss-army knife because you hit
your thumb with a hammer instead of the nail.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Attila Feher Guest
|
Posted: Tue Sep 16, 2003 8:37 pm Post subject: Re: typedef decalrations |
|
|
Francis Glassborow wrote:
[SNIP]
| Quote: | But why not use the simple answer of writing the original declaration
correctly:
typedef char D2[1400];
|
Like I did! I am a good boy.
| Quote: | ? There is no point in reaching for a Swiss-army knife because you hit
your thumb with a hammer instead of the nail.
|
Hm. Why would I want to hit my thumb with a nail?
--
Attila aka WW
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|