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

Confused by compiler warning

P: n/a
I am playing with some code that has been automatically generated
from ASN.1 data specification found in RFC 3280. One of the structures
generated reads as follows:

typedef struct TBSCertList {
Version_t *version /* OPTIONAL */;
AlgorithmIdentifier_t signature;
Name_t issuer;
Time_t thisUpdate;
struct Time *nextUpdate /* OPTIONAL */;
struct revokedCertificates {
A_SEQUENCE_OF(struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions *crlEntryExtensions /
* OPTIONAL */;

/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} ) list;

/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} *revokedCertificates;
struct Extensions *crlExtensions /* OPTIONAL */;

/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} TBSCertList_t;

/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_TBSCertList;
}

where A_SEQUENCE_OF() is defined as

#define A_SEQUENCE_OF(type) \
struct { \
type **array; \
int count; /* Meaningful size */ \
int size; /* Allocated size */ \
void (*free)(type *); \
}

The preprocessor expands this as

typedef struct TBSCertList {
Version_t *version;
AlgorithmIdentifier_t signature;
Name_t issuer;
Time_t thisUpdate;
struct Time *nextUpdate;
struct revokedCertificates {
struct {
struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions *crlEntryExtensions;
asn_struct_ctx_t _asn_ctx;
} **array;
int count;
int size;
void (*free) (struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions * crlEntryExtensions;
asn_struct_ctx_t _asn_ctx;
} *);
} list;

asn_struct_ctx_t _asn_ctx;
} *revokedCertificates;
struct Extensions *crlExtensions;

asn_struct_ctx_t _asn_ctx;
} TBSCertList_t;

This compiles all right, but the GCC compiler generates the
following warning:

TBSCertList.h:47: warning: structure defined inside parms
TBSCertList.h:47: warning: `struct Member' declared inside parameter list
TBSCertList.h:47: warning: its scope is only this definition or
declaration, which is probably not what you want

Line 47 is the line that reads

} ) list;

in the code above, before the preprocessing.

Now I want to believe that this code is generated the way it is
generated for some good reason. What I do not understand is what the
compiler is complaining about. Anybody care to explain? What is it about
struct Member that the compiler reckons that that's not what we want?

Feb 6 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"James H. Newman" <NewJa...@exicite.comwrote:
<snip>
* * * * This compiles all right, but the GCC compiler
generates the following warning:

TBSCertList.h:47: warning: structure defined inside parms
TBSCertList.h:47: warning: `struct Member' declared inside parameter list
TBSCertList.h:47: warning: its scope is only this definition or
declaration, which is probably not what you want
This is Question 11.5 in the FAQ...

http://c-faq.com/ansi/structinproto.html

--
Peter
Feb 6 '08 #2

P: n/a
Peter Nilsson wrote:
"James H. Newman" <NewJa...@exicite.comwrote:
<snip>
>* * * * This compiles all right, but the GCC compiler
generates the following warning:

TBSCertList.h:47: warning: structure defined inside parms
TBSCertList.h:47: warning: `struct Member' declared inside parameter list
TBSCertList.h:47: warning: its scope is only this definition or
declaration, which is probably not what you want

This is Question 11.5 in the FAQ...

http://c-faq.com/ansi/structinproto.html
That is about function parameters, not macro parameters.
--
Army1987 (Replace "NOSPAM" with "email")
Feb 6 '08 #3

P: n/a
"James H. Newman" wrote:
>
I am playing with some code that has been automatically generated
from ASN.1 data specification found in RFC 3280. One of the structures
generated reads as follows:
[...snip...]
The preprocessor expands this as

typedef struct TBSCertList {
[...]
struct revokedCertificates {
struct {
struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions *crlEntryExtensions;
asn_struct_ctx_t _asn_ctx;
} **array;
int count;
int size;
void (*free) (struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions * crlEntryExtensions;
asn_struct_ctx_t _asn_ctx;
} *);
} list;
[...]
} TBSCertList_t;

This compiles all right, but the GCC compiler generates the
following warning:

TBSCertList.h:47: warning: structure defined inside parms
TBSCertList.h:47: warning: `struct Member' declared inside parameter list
TBSCertList.h:47: warning: its scope is only this definition or
declaration, which is probably not what you want

Line 47 is the line that reads

} ) list;

in the code above, before the preprocessing.
[...]

Look at this part in the middle of the macro expansion:
void (*free) (struct Member {
CertificateSerialNumber_t userCertificate;
Time_t revocationDate;
struct Extensions * crlEntryExtensions;
asn_struct_ctx_t _asn_ctx;
} *);
You are declaring a member of the struct called "free", which is
a function pointer, and you are prototyping that function. Within
that prototype, you are declaring a struct called "Member". This
"struct Member" is not the same "struct Member" that you define a
few lines earlier, because it is an actual definition, not just a
reference. (Yes, it is the same name and an identical layout, but
that doesn't matter as far as the warning is concerned.)

Consider this valid, though probably useless, snippet:

struct foo { int a; int b; };
extern void func1( struct foo *foopt );
extern void func2( struct foo { float a; float b; } *foopt );

Just as the third warning states:

its scope is only this definition or declaration, which is
probably not what you want

Change it so that the expansion is:

void (*free)(struct Member *);

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Feb 6 '08 #4

P: n/a
Army1987 <ar******@NOSPAM.itwrites:
Peter Nilsson wrote:
>"James H. Newman" <NewJa...@exicite.comwrote:
<snip>
>>* * * * This compiles all right, but the GCC compiler
generates the following warning:

TBSCertList.h:47: warning: structure defined inside parms
TBSCertList.h:47: warning: `struct Member' declared inside parameter list
TBSCertList.h:47: warning: its scope is only this definition or
declaration, which is probably not what you want

This is Question 11.5 in the FAQ...

http://c-faq.com/ansi/structinproto.html
That is about function parameters, not macro parameters.
The warning messages are about function parameters, not macro
parameters. The function parameter declaration happens to be within a
macro expansion, but that's irrelevant. (By the time the compiler
gets to the phase where it produces the warning, all macros have been
processed and are no longer visible.)

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 6 '08 #5

P: n/a
Keith Thompson wrote:
Army1987 <ar******@NOSPAM.itwrites:
>That is about function parameters, not macro parameters.

The warning messages are about function parameters, not macro
parameters. The function parameter declaration happens to be within a
macro expansion, but that's irrelevant. (By the time the compiler
gets to the phase where it produces the warning, all macros have been
processed and are no longer visible.)
Oh, I had missed the declaration of free.

--
Army1987 (Replace "NOSPAM" with "email")
Feb 6 '08 #6

P: n/a
"Jack Klein" <ja*******@spamcop.netwrote in message
news:o4********************************@4ax.com...
[snip: excellent explanation of what the warning means]

If somebody changes the definition of the struct type in one place or
the other, but not all places, then suddenly you have problems,
undefined behavior, "mysterious" defects, etc.

It would be much better to put the definition of struct Member in a
header, and include that header everywhere it is used.
While I'd agree with all of the above if the code were maintained by a
human, it should be pointed out that the OP stated this code is
automatically generated. As long as one trusts that tool to keep the
definitions consistent (and in this example, it obviously does so), the code
is safe and the warning can be ignored or disabled. If the tool breaks,
you'll likely have far, far bigger problems than a simple compiler warning.

I'd, however, look into whether it's possible to modify the tool to generate
the code a bit more like a human would, i.e. in a way that doesn't trigger
this warning.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

Feb 8 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.