473,748 Members | 7,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 */;
AlgorithmIdenti fier_t signature;
Name_t issuer;
Time_t thisUpdate;
struct Time *nextUpdate /* OPTIONAL */;
struct revokedCertific ates {
A_SEQUENCE_OF(s truct Member {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions *crlEntryExtens ions /
* 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;
} *revokedCertifi cates;
struct Extensions *crlExtensions /* OPTIONAL */;

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

/* Implementation */
extern asn_TYPE_descri ptor_t asn_DEF_TBSCert List;
}

where A_SEQUENCE_OF() is defined as

#define A_SEQUENCE_OF(t ype) \
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;
AlgorithmIdenti fier_t signature;
Name_t issuer;
Time_t thisUpdate;
struct Time *nextUpdate;
struct revokedCertific ates {
struct {
struct Member {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions *crlEntryExtens ions;
asn_struct_ctx_ t _asn_ctx;
} **array;
int count;
int size;
void (*free) (struct Member {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions * crlEntryExtensi ons;
asn_struct_ctx_ t _asn_ctx;
} *);
} list;

asn_struct_ctx_ t _asn_ctx;
} *revokedCertifi cates;
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:4 7: warning: structure defined inside parms
TBSCertList.h:4 7: warning: `struct Member' declared inside parameter list
TBSCertList.h:4 7: 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 3681
"James H. Newman" <NewJa...@exici te.comwrote:
<snip>
* * * * This compiles all right, but the GCC compiler
generates the following warning:

TBSCertList.h:4 7: warning: structure defined inside parms
TBSCertList.h:4 7: warning: `struct Member' declared inside parameter list
TBSCertList.h:4 7: 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...@exici te.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 revokedCertific ates {
struct {
struct Member {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions *crlEntryExtens ions;
asn_struct_ctx_ t _asn_ctx;
} **array;
int count;
int size;
void (*free) (struct Member {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions * crlEntryExtensi ons;
asn_struct_ctx_ t _asn_ctx;
} *);
} list;
[...]
} TBSCertList_t;

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

TBSCertList.h:4 7: warning: structure defined inside parms
TBSCertList.h:4 7: warning: `struct Member' declared inside parameter list
TBSCertList.h:4 7: 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 {
CertificateSeri alNumber_t userCertificate ;
Time_t revocationDate;
struct Extensions * crlEntryExtensi ons;
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******@NOSPA M.itwrites:
Peter Nilsson wrote:
>"James H. Newman" <NewJa...@exici te.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_Keit h) <ks***@mib.or g>
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******@NOSPA M.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*******@spam cop.netwrote in message
news:o4******** *************** *********@4ax.c om...
[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
7356
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 `char *' In Line 19 of my file 'robot.cpp' I declare the constructor of class robot like:
14
1909
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
3188
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 i386-pc-solaris2.9. Seeing reference to gcc-2.7.2 in the Makefile of the code, I downloaded it and compiled in my home directory. Then changed the referenes of LIBDIR and INCLUDES to this installation .and ran with g++ for 2.7.2 then there are still...
34
6440
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 started messing around in Plan 9, and that sort of thing is totally no go there :). Is this correct to allocate memory for my struct? It works on my computer, but I'm suspicious that I'm doing it wrong. --
29
2523
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
4878
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 Try Set up the database read and do it. Catch ex as system.exception exception stuff here Finally
11
2022
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 class, that's bounded to a base class reference to delay the destruction of the actual object to the end of the reference scope. Actually, I don't use the reference: the code that matters is in the destructor, and I want it to be executed at the end...
6
17110
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 foo(char loc) {
9
1760
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 better. What is difference between using : #include <iostream> #include <iostream.h> Bloodshed Dev c++ (MinGW compiler) reports a warning for second one as:
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.