473,386 Members | 1,864 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.

Confused by compiler warning

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
6 3648
"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
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
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: G. Peter | last post by:
Hi there, I've a 'funny' error message of my compiler (g++ 2.95.4) that tells me: robot.cpp: In method `Robot::Robot()': robot.cpp:19: warning: deprecated conversion from string constant to...
14
by: mshetty | last post by:
Hi, I get an error "Warning: b::a_method hides the virtual function a::a_method()." on compiling the following code.. #include <iostream.h> class a {
1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
34
by: Richard Hunt | last post by:
I'm sorry for asking such a silly question, but I can't quite get my head around malloc. Using gcc I have always programmed in a lax C/C++ hybrid (which I suppose is actually c++). But I have...
29
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
6
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void...
9
AmberJain
by: AmberJain | last post by:
Hello, I had just started with C++ programming. I know that I will get answer to this question when I read "C++ Primer" book completely (in detail), but I thought that getting answer now is much...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.