473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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! ]
Jul 19 '05 #1
11 9731
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:sC*********************@newssvr12.news.prodig y.com...
| 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.
Note: for quick answers to simple problems, posting
to comp.lang.c++ (without cross-posting to the
*.moderated one) will provide you with faster
responses...

hth
--
http://ivan.vecerina.com
Jul 19 '05 #2
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:sC*********************@newssvr12.news.prodig y.com...
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
rh*******@pobox.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #3
Andrew Chalk wrote:
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! ]
Jul 19 '05 #4
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:sC*********************@newssvr12.news.prodig y.com...
| 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! ]
Jul 19 '05 #5
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> writes:

| why can't I:
|
| typedef char[1400] D2;

try

typedef char D2[1400];

--
Gabriel Dos Reis <gd*@integrable-solutions.net>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #6
In article <sC*********************@newssvr12.news.prodigy.co m>,
Andrew Chalk wrote:
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! ]
Jul 19 '05 #7
On Mon, 15 Sep 2003 05:49:01 -0400, Andrew Chalk wrote:
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! ]
Jul 19 '05 #8
Andrew Chalk wrote:
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! ]
Jul 19 '05 #9
> 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! ]
Jul 19 '05 #10
In article <19**************************@posting.google.com >, Dan
McLeran <da***********@seagate.com> writes
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! ]
Jul 19 '05 #11
Francis Glassborow wrote:
[SNIP]
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.
? 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! ]
Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
15
by: Merrill & Michele | last post by:
typedef struct { WORD versionNumber; WORD offset; } MENUITEMTEMPLATEHEADER; This is from vol 5 of unnamed platform's programmer's reference. I could make this conforming by enclosing...
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
12
by: vvv | last post by:
Hi All, Do we have anything in .NET which is equivalent to C++'s Typedef . Regards, Vasanth
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
16
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.