struct teststruct {
int data[100]; };
teststruct one;
teststruct *testarray[17];
testarray[4] = &one;
Results in a compilation error on the last line above:
'testarray' : missing storage-class or type specifiers
Why???
--
comp.lang.c.moderated - moderation address: cl...@plethora.net
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
>
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
Try
struct teststruct *testarray[17];
This is C, not C++.
--
__ Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ You are a beautiful surprise
-- India Arie
rlc
You don't show enough context, but I'm guessing that the above code
isn't inside a function. The last line is a statement, not a
declaration; statements can only occur inside functions (including
main()).
I'm guessing you tried to compile it with a C++ compiler. A C
compiler would complain about "teststruct one;". You need to refer to
the type as "struct teststruct", not just "teststruct".
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
> This code:
>
> struct teststruct {
> int data[100]; };
If your code is actually C, the declaration above creates a type which
has the name "struct teststruct".
> teststruct one;
If your code is actually C, the definition above is an error requiring
a diagnostic. There is no such thing as a "teststruct", and a
"teststruct" is not a "struct teststruct".
> teststruct *testarray[17];
Likewise, the line above is not valid C.
> testarray[4] = &one;
>
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
If this code is C++, you need to go elsewhere. If you have real C
code, copy the smallest possible amount from the real source and paste
it as text into your message. Do not retype it into something that
can't compile. And copy and paste the real error message text as
well.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
You've created an array that'll hold pointers to type teststruct
but you've not populated the array yet, e.g.,
teststruct *p_struct1 = NULL;
testarray[0] = p_struct1;
testarray[0] = &one;
or
teststruct *p_struct1 = &one;
testarray[0] = p_struct1;
etc...
-Joe
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
You've created an array that'll hold pointers to type teststruct
but you've not populated the array yet, e.g.,
teststruct *p_struct1 = NULL;
testarray[0] = p_struct1;
testarray[0] = &one;
or
teststruct *p_struct1 = &one;
testarray[0] = p_struct1;
etc...
-Joe
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
You've created an array that'll hold pointers to type teststruct
but you've not populated the array yet, e.g.,
teststruct *p_struct1 = NULL;
testarray[0] = p_struct1;
testarray[0] = &one;
or
teststruct *p_struct1 = &one;
testarray[0] = p_struct1;
etc...
-Joe
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
You've created an array that'll hold pointers to type teststruct
but you've not populated the array yet, e.g.,
teststruct *p_struct1 = NULL;
testarray[0] = p_struct1;
testarray[0] = &one;
or
teststruct *p_struct1 = &one;
testarray[0] = p_struct1;
etc...
-Joe
>This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
>
>Results in a compilation error on the last line above:
>'testarray' : missing storage-class or type specifiers
>Why???
Maybe you should use struct teststruct one, etc since omitting the
struct is specific to C99.
<<Remove the del for email>>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
>
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
Because you haven't defined teststruct. You've defined struct
teststruct, but that's not the same thing. C is not C++.
BTW, I'd have expected an error for the declaration of one, as well.
Richard
In article <clcm-2004...@plethora.net>, pd42 wrote:
> This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
struct teststruct one;
> teststruct *testarray[17];
struct teststruct *testarray[17];
> testarray[4] = &one;
>
> Results in a compilation error on the last line above:
> 'testarray' : missing storage-class or type specifiers
> Why???
Because teststruct is not a type, struct teststruct is. You could make
the rest work by replacing your structure definition with this:
typedef struct {
int data[100];
} teststruct;
This makes teststruct a label associated with the structure type. The
type, however, is still struct { int data[100;}.
Cheers,
Dave.
> struct teststruct {
> int data[100]; };
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
>
> Results in a compilation error on the last line above:
If so, you're in the wrong newsgroup. No C compiler would accept the
third line of that sample, because you don't have a typedef of
'teststruct' in sight. You must have been compiling this as C++. The
newsgroup dealing with that is a couple doors down the hall.
--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Is this the complete code? The statement:
testarray[4] = &one;
is not valid outside of a function.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
>This code:
>
> struct teststruct {
> int data[100]; };
>
> teststruct one;
> teststruct *testarray[17];
> testarray[4] = &one;
>
>Results in a compilation error on the last line above:
>'testarray' : missing storage-class or type specifiers
>Why???
Your code is valid C++, but not C.
In C, teststruct is a structure tag, not a type, and struct teststruct
is a type; whereas I believe in C++, a tag is automatically a type.
You are using a structure tag in your variable definitions where a
type is required.
You can define teststruct as a type definition as follows:
typedef struct teststruct
{
int data[100];
} teststruct;
or you can correct your variable definitions as follows:
struct teststruct one;
struct teststruct *testarray[17];
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian....@CSi.com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply
No, it's specific to C++ (or whatever nearly-C-compatible language
this might be).
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <clcm-2004...@plethora.net>, Jpoirier wrote:
> You've created an array that'll hold pointers to type teststruct
> but you've not populated the array yet, e.g.,
He doesn't need to. The storage is there, and as long as he doesn't
read uninitialised values, he should be fine.
> teststruct *p_struct1 = NULL;
> testarray[0] = p_struct1;
> testarray[0] = &one;
This serves absolutely no purpose. You have also duplicated the original
poster's mistake by not using struct teststruct. And I don't understand
what you're trying to achieve with p_struct1. Why not do the equivalent
testarray[0] = NULL;
? Then again, since you over-write this value straight away afterwards,
the initialisation serves no purpose anyway.
testarray[0] = &one; is a perfectly fine initialisation.
Cheers,
Dave.