Click here to Skip to main content
14,695,439 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everyone,

I have the following setup declare lots of stuff in a header file and use the header file in the main c file

So in the header file I have an enum declaration as so
void NewFunc(Stuff s,char c);

typedef enum Stuff

//AND in main
#include "header.h"

//and try and use the function
void NewFunc(Stuff s,char c)
   //Blah Blah Blah......

It comes up with the following fault, when I make the program: expected ')' before s

Not sure if I declared the enum wrong or the makefile I use is broken :/.....

Using Ubuntu and VIM...


The definition of NewFunc contains a forward reference (not allowed) to the enum, hence the error message. Move it below the enum definition.
H.Brydon 21-Jan-13 10:35am
Ding ding ding ... +5
Richard MacCutchan 21-Jan-13 12:26pm
See my response to SA.
fjdiewornncalwe 21-Jan-13 11:15am
Richard MacCutchan 21-Jan-13 12:26pm
See my response to SA.
Sergey Alexandrovich Kryukov 21-Jan-13 11:26am
5. —SA
Richard MacCutchan 21-Jan-13 12:26pm
Thanks guys, more points than I've received in one go for a long time.
... and remove that typedef. That is an old C convention to declare enumarations as

typedef enum {
    // something

In C++ enums are first class citizens and you simply write
enum MyEnum {
    // something
Sergey Alexandrovich Kryukov 21-Jan-13 11:26am
5! —SA
nv3 21-Jan-13 11:39am
Thanks, SA!
Seems all your suggestions don't work.... removed the typedef, and yes I had thought about the scope issue of it being declared before the enum... I originally had it below the enum....

A bit quick to give each other +5 to your solutions that don't work.... :p
Richard MacCutchan 22-Jan-13 5:23am
Yes, our suggestions do work because most of us actually test them before posting here. Show the code you have now and any associated compiler messages.
Richard MacCutchan 22-Jan-13 5:25am
Also, please do not post comments or questions as solutions. Use the "Have a Question or Comment?" button beneath our solutions to respond.
H.Brydon 22-Jan-13 11:42am
Richard's comment that you use enum Stuff in the NewFunc forward declaration before defining "Stuff" is the cause of the error. nv3's comment that you should use newer syntax for the enum is also correct.

Both comments are correct and valid, solve the question you asked and show you how to improve your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900