473,698 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning when using an ENUM in a Function prototype

Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions.h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"

I tried removing the "enum" word from the prototype declaration, but
then it fails to compile because it
doesn't know what DAY is. What is the problem?!

Thanks!
Oct 8 '08 #1
8 8541
benn wrote:
Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions.h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions.c contains:

#include "Defines.h"
#include "DayFunctions.h "
#include <stdio.h>
>
void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "
#include <stdio.h>
>
void main (void)
int main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
putc('\n', stdout);
return (EXIT_SUCCESS);
}
Then your code is ok.
>

The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
I think you have mispelled the name DAY in your _actual_ code (i.e., not
the one you have posted). The code that you have posted compiles fine here.
>
I tried removing the "enum" word from the prototype declaration, but
then it fails to compile because it
doesn't know what DAY is. What is the problem?!

Thanks!

--
Pietro Cerutti
Oct 8 '08 #2
benn <be*****@hotmai l.comwrites:
Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions.h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]

DayFunctions.h refers to "enum DAY", but the declaration is not visible.

Add
#include "Defines.h"
to DayFunctions.h.

And fix your declaration of main; it's "int main(void)".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 8 '08 #3
Keith Thompson wrote:
benn <be*****@hotmai l.comwrites:
>Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions .h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions .c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]

DayFunctions.h refers to "enum DAY", but the declaration is not visible.

Add
#include "Defines.h"
to DayFunctions.h
Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?

[snip "fix main declaration"]

--
Pietro Cerutti
Oct 8 '08 #4
Keith Thompson wrote:
benn <be*****@hotmai l.comwrites:
>Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions .h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions .c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]

DayFunctions.h refers to "enum DAY", but the declaration is not visible.

Add
#include "Defines.h"
to DayFunctions.h
Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?

[snip "fix main declaration"]

--
Pietro Cerutti
Oct 8 '08 #5
Pietro Cerutti wrote:
Keith Thompson wrote:
>benn <be*****@hotmai l.comwrites:
>>Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions. h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions. c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]

DayFunctions .h refers to "enum DAY", but the declaration is not visible.

Add
#include "Defines.h"
to DayFunctions.h

Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?
Sorry for the double post, giganews is not behaving nicely to me today...
>
[snip "fix main declaration"]

--
Pietro Cerutti
Oct 8 '08 #6
Pietro Cerutti <gahr_SPAM_gahr _ME_chwrites:
Keith Thompson wrote:
>benn <be*****@hotmai l.comwrites:
>>Here's the setup...

Defines.h file contains:
enum DAY { monday, tueday };

DayFunctions. h contains prototype:
void printIsMonday ( enum DAY currentDay);

DayFunctions. c contains:

#include "Defines.h"
#include "DayFunctions.h "

void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}

Main.c contains:

#include "Defines.h"
#include "DayFunctions.h "

void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definition or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]
DayFunctions .h refers to "enum DAY", but the declaration is not
visible.
Add
#include "Defines.h"
to DayFunctions.h

Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?
Yes, probably so.

Ideally, each header should have a #include for any headers containing
declarations that it depends on, and each header should have include
guards so that its contents are only included once in each translation
unit. In the code the OP presented, a #include for "DayFunctions.h "
requires a preceding #include for "Defines.h" . The posted code does
satisfy that requirement (which I didn't notice when I first read it),
but IMHO it's poor style -- and it's very likely, given that the OP is
getting that warning message, that this problem *does* occur in his
real code.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 8 '08 #7
On Oct 8, 12:42*pm, Keith Thompson <ks...@mib.orgw rote:
Pietro Cerutti <gahr_SPAM_gahr _ME_chwrites:
Keith Thompson wrote:
benn <benn...@hotmai l.comwrites:
Here's the setup...
>Defines.h file contains:
enum *DAY *{ monday, tueday };
>DayFunctions .h contains prototype:
void printIsMonday ( enum DAY currentDay);
>DayFunctions .c contains:
>#include "Defines.h"
#include "DayFunctions.h "
>void printIsMonday ( enum DAY currentDay)
{
* * * if (currentDay == monday)
* * * * printf("Monday! ");
}
>Main.c contains:
>#include "Defines.h"
#include "DayFunctions.h "
>void main (void)
{
* * * enum DAY * eDayVariable;
* * * eDayVariable = monday;
* * * printIsMonday( eDayVariable);
}
>The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. *Its scope is only
definition or declartion, which is
probably not what you want. *Parameter has incomplete type.
"
[...]
DayFunctions.h refers to "enum DAY", but the declaration is not
visible.
Add
* * #include "Defines.h"
to DayFunctions.h
Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?

Yes, probably so.

Ideally, each header should have a #include for any headers containing
declarations that it depends on, and each header should have include
guards so that its contents are only included once in each translation
unit. *In the code the OP presented, a #include for "DayFunctions.h "
requires a preceding #include for "Defines.h" . *The posted code does
satisfy that requirement (which I didn't notice when I first read it),
but IMHO it's poor style -- and it's very likely, given that the OP is
getting that warning message, that this problem *does* occur in his
real code.

--
Keith Thompson (The_Other_Keit h) ks...@mib.org *<http://www.ghoti.net/~kst>
Nokia
"We must do something. *This is something. *Therefore, we must do this."
* * -- Antony Jay and Jonathan Lynn, "Yes Minister"
Thanks, I always put include guards, and generally I thought it was
*not* good style to put include files inside of include files. I'll
look it up in Effective C++ (Myers) to see if its mentioned!

Including the Defines.h inside DayFunction.h did indeed eliminate the
warning, but why?? Both .c files include the Defines header file
first, and the compiler therefore know about the enum type before
tackling the DayFunction.h file.

Incidentally, if I remove the prototype all together from
DayFunction.h, then I get the (relatively benign) warning that
printIsMonday is being declared implicitly.

Oct 8 '08 #8
benn wrote, On 08/10/08 21:30:
On Oct 8, 12:42 pm, Keith Thompson <ks...@mib.orgw rote:
>Pietro Cerutti <gahr_SPAM_gahr _ME_chwrites:
>>Keith Thompson wrote:
benn <benn...@hotmai l.comwrites:
Here's the setup...
Defines.h file contains:
enum DAY { monday, tueday };
DayFunction s.h contains prototype:
void printIsMonday ( enum DAY currentDay);
DayFunction s.c contains:
#include "Defines.h"
#include "DayFunctions.h "
void printIsMonday ( enum DAY currentDay)
{
if (currentDay == monday)
printf("Monday! ");
}
Main.c contains:
#include "Defines.h"
#include "DayFunctions.h "
void main (void)
{
enum DAY eDayVariable;
eDayVariable = monday;
printIsMonday( eDayVariable);
}
The warning message the compiler gives for the prototype declaration
line in DayFunctions.h:
"
"enum DAY" declared inside parameter list. Its scope is only
definitio n or declartion, which is
probably not what you want. Parameter has incomplete type.
"
[...]
DayFunctions .h refers to "enum DAY", but the declaration is not
visible.
Add
#include "Defines.h"
to DayFunctions.h
Isn't it so that both DayFunctions.h and Defines.h get included in the
same translation unit, making the enum visible from the T.U.?
Yes, probably so.

Ideally, each header should have a #include for any headers containing
declarations that it depends on, and each header should have include
guards so that its contents are only included once in each translation
unit. In the code the OP presented, a #include for "DayFunctions.h "
requires a preceding #include for "Defines.h" . The posted code does
satisfy that requirement (which I didn't notice when I first read it),
but IMHO it's poor style -- and it's very likely, given that the OP is
getting that warning message, that this problem *does* occur in his
real code.

--
Keith Thompson (The_Other_Keit h) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Please don't quote peoples signatures, the bit typically after the "-- "
unless you are commenting on them.
Thanks, I always put include guards, and generally I thought it was
*not* good style to put include files inside of include files. I'll
look it up in Effective C++ (Myers) to see if its mentioned!
Why look in a C++ book to find out what is good style for C? Wouldn't
looking in a C book make more sense?
Including the Defines.h inside DayFunction.h did indeed eliminate the
warning, but why??
Because you code is not the same as the code you posted. I suggest
looking on line 42 for the answer.
Both .c files include the Defines header file
first, and the compiler therefore know about the enum type before
tackling the DayFunction.h file.
Either there is a bug in the compiler, which is *very* unlikely, or
there is a bug in your code.
Incidentally, if I remove the prototype all together from
DayFunction.h, then I get the (relatively benign) warning that
printIsMonday is being declared implicitly.
That is a far from benign warning (in general rather than in this
specific instance), it is a warning that indicates a potentially serious
problem that in some cases on some systems can cause the program to crash.
--
Flash Gordon
If spamming me sent it to sm**@spam.cause way.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Oct 8 '08 #9

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

Similar topics

11
3228
by: michael potter | last post by:
I would like to code a prototype that returns an enum, but not declare the enum. This works on several systems and compilers, but fails on aix xlc. Here is the sample code: enum anEnum someFunc(void); when i run:
16
5840
by: jose_luis_fdez_diaz_news | last post by:
Hi, If I don't include <libgen.h> I get then warnig below in regcmp call: warning: improper pointer/integer combination: op "=" but if I include it the warning is not shown, but them program compiles fine. What is the warning shown ?
5
3869
by: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have to drop the "enum" keyword from my member variable declaration to keep the compiler happy. Shouldn't I technically be able to use the "enum" keyword without a warning?
8
8219
by: Mat | last post by:
Hi all. This function is a GNU extension ok... so pls dont start with "this is not standard C", "go to comp.*.unix"... here I have more probability to get a good reply. BTW, when I compile my app I get: warning: implicit declaration of function `strnlen' And I hate this :) Ok, it's only a stupid warning in this case but I would like to know
92
6199
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
3
4753
by: harrym55 | last post by:
Hi, I receive warning for the following enum: Public Enum enumMinOrMax Min Max End Enum Warning 20 Type of parameter 'MinOrMax' is not CLS-compliant.
0
8672
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
8600
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
9156
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
9021
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
8892
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
8860
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...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3038
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.