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

Warning when using an ENUM in a Function prototype

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
benn <be*****@hotmail.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_Keith) 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

P: n/a
Keith Thompson wrote:
benn <be*****@hotmail.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

P: n/a
Keith Thompson wrote:
benn <be*****@hotmail.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

P: n/a
Pietro Cerutti wrote:
Keith Thompson wrote:
>benn <be*****@hotmail.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

P: n/a
Pietro Cerutti <gahr_SPAM_gahr_ME_chwrites:
Keith Thompson wrote:
>benn <be*****@hotmail.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_Keith) 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

P: n/a
On Oct 8, 12:42*pm, Keith Thompson <ks...@mib.orgwrote:
Pietro Cerutti <gahr_SPAM_gahr_ME_chwrites:
Keith Thompson wrote:
benn <benn...@hotmail.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_Keith) 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

P: n/a
benn wrote, On 08/10/08 21:30:
On Oct 8, 12:42 pm, Keith Thompson <ks...@mib.orgwrote:
>Pietro Cerutti <gahr_SPAM_gahr_ME_chwrites:
>>Keith Thompson wrote:
benn <benn...@hotmail.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_Keith) 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.causeway.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 discussion thread is closed

Replies have been disabled for this discussion.