UCHAR undeclared

T

tirzan

Hi all,

I'm trying to reuse a piece of code in C, but I have some problems, I
hope you can help me.

summarizing I have a:

typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;

and a function:

void foo( bufferType typeIn ){
...
}


when in the main I call the function foo, with for example:

foo(UCHAR);

I have an error: "UCHAR undeclared"

any hint?

thanks a lot,
tirzan
 
C

Chris Dollin

tirzan said:
I'm trying to reuse a piece of code in C, but I have some problems, I
hope you can help me.

summarizing

Don't.

Show us the /exact/ code. If you don't know what's wrong, how
can you know what's relevant?
I have a:

typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;

and a function:

void foo( bufferType typeIn ){
...
}


when in the main I call the function foo, with for example:

foo(UCHAR);

I have an error: "UCHAR undeclared"

any hint?

I /guess/ you haven't included the declaration of `foo` or
of `bufferType` in the compilation unit containing `main`,
but since I can't see your code, it's just a guess.
 
F

Flash Gordon

tirzan said:
Hi all,

I'm trying to reuse a piece of code in C, but I have some problems, I
hope you can help me.

summarizing I have a:

Hello Mr Mechanic, my car won't start. Here are the sparc plugs and the
ignition key, what is wrong with my car?

Always provide a small *complete* example illustrating the problem. I
would say compilable, but obviously if as is the case here the problem
is you can't compile it then that is not appropriate.
typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;

You do know that typdef does not really create a new type in C don't you.
and a function:

void foo( bufferType typeIn ){

So for this function there is nothing to stop any integer from being
passed in, you are not limited to the enumerations.
...
}


when in the main I call the function foo, with for example:

foo(UCHAR);

I have an error: "UCHAR undeclared"

any hint?

Yes, the definition of UCHAR is not in scope at the point where you call
foo. Either it is before you define it, in a different file, or
something. Had you provided your actual code people could tell you the
actual problem.
 
P

pete

tirzan said:
Hi all,

I'm trying to reuse a piece of code in C, but I have some problems, I
hope you can help me.

summarizing I have a:

typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;

and a function:

void foo( bufferType typeIn ){
...
}

when in the main I call the function foo, with for example:

foo(UCHAR);

I have an error: "UCHAR undeclared"

any hint?

Not really.

/* BEGIN new.c */

typedef enum {
UCHAR,
SCHAR,
INT
} bufferType;

void foo(bufferType typeIn)
{
typeIn;
}

int main(void)
{
foo(SCHAR);
return UCHAR;
}

/* END new.c */
 
M

Martin Ambuhl

tirzan said:
summarizing I have a:
typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;
and a function:
void foo( bufferType typeIn ){
...
}
when in the main I call the function foo, with for example:
foo(UCHAR);
I have an error: "UCHAR undeclared"
any hint?

Please post your real code. I believe you have misdiagnosed your
problem. The following code incorporates *all* the information you ahve
given. Please see if it produces the diagnostic that you report.

typedef enum
{
UCHAR,
SCHAR,
INT
} bufferType;

void foo(bufferType typeIn)
{
/* ... */
}

int main(void)
{
foo(UCHAR);
return 0;
}
 
T

tirzan

tirzan said:
summarizing I have a:

typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;
any hint?

thanks everybody, I solved the problem: other UCHARs somewhere in the
code (with different enum order), then the solution was:

typedef enum{
t_UCHAR,
t_SCHAR,
t_INT
} bufferType;

in the code. Now it runs... not really elegant... but it compile ;-)

thank you guys, and sorry if i didn't put the code, but I was working
with at least 10 files open, I'm not so sadistic to let you read so
much code for me ;-)


bye,
tirzan
 
S

Sjouke Burry

tirzan said:
Hi all,

I'm trying to reuse a piece of code in C, but I have some problems, I
hope you can help me.

summarizing I have a:

typedef enum{
UCHAR,
SCHAR,
INT
} bufferType;

and a function:

void foo( bufferType typeIn ){
...
}


when in the main I call the function foo, with for example:

foo(UCHAR);

I have an error: "UCHAR undeclared"

any hint?

thanks a lot,
tirzan
Typedef is no declaration ,only

BufferType typeIn;

somewhere in your scope is a declaration.

Typedef defines a type(as the name suggests),
and can be used to declare a variable.
 
P

pete

Sjouke said:
Typedef is no declaration ,only

BufferType typeIn;

somewhere in your scope is a declaration.

Typedef defines a type(as the name suggests),
and can be used to declare a variable.

Defining a type is also a declaration.

All definitions in a translation unit are also declarations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top