GCC error: expected ‘)’ before <function protoyprmeter> parameter - c

In a header file
extern void Trace_Communication(communicationBlock_t mdbMessage);
gives error: expected ‘)’ before ‘mdbMessage’
I am sure that communicationBlock_t is in scope (and reliaze that it would be more efficient to pass a pointer)
If I copy the declaration of communicationBlock_t just before the extern offending line, the error is
error: conflicting types for ‘communicationBlock_t’
note: previous declaration of ‘communicationBlock_t’ was here
Which seems to imply that the offending line has access to the declaration of communicationBlock_t
I guess that I am overlooking something trivial and obvious, but I have been coding all night and can no longer think straight ...
What am I doing wrong? Thanks 1 ,000,000
Update: my guess is that it's an include file tangle ...
typedef struct
{
communicationMessage_t message;
uint8_t length;
#ifdef TESTING
char commandName[32]; // for testing porpoises
DoRunTimeChecks runTimeCheckCallback;
#endif
} communicationBlock_t;

Looks to me like you're using a variable as a type name. What does the declaration of communicationBlock_t look like?

Sorry, folks. It was, as I suspected a deady embrace in #include files

Related

Redefinition of structure

Below is the code of my header file trie.h.
The compiler keep showing the following error:
In file included from speller.c:11:
./trie.h:3:8: error: redefinition of 'letter'
struct letter
^
./trie.h:3:8: note: previous definition is here
struct letter
^
1 error generated.
make: *** [speller.o] Error 1
The code:
struct letter
{
int is_word;
struct letter* arr[27];
};
// fuctions
struct letter* create_trie();
void free_trie(struct letter* trie);
Most likely your file gets included multiple times, hence the redefinition error.
To avoid this problem use include guards:
#ifndef HEADERNAME_DEFINED
#define HEADERNAME_DEFINED
// your code goes here.
#endif // HEADERNAME_DEFINED
or you can use non-standard preprocessor directive like #pragma once to do the job. It results in less code, and sometimes faster compilation speed.
Put that on top of your file:
#pragma once
// your code goes here
Note: The comment (// HEADERNAME_DEFINED part) after #endif isn't necessary. It is just a hint for programmer to know what belongs together.

Why does this static funtion have three prefixes?

I'm trying to build a driver for my SD card, but I get an error on this line:
static void __devexit rtsx_remove(struct pci_dev *pci)
Saying:
/home/kenkron/Downloads/rts_pstor/rtsx.c:916:22: error: expected ‘=’,‘,’,‘;’, ‘asm’ or ‘__attribute__’ before ‘rtsx_probe’ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
Why is __devexit before the function name, and how is it supposed to work?
Edit: my question is about what __devexit is in the context of the function definition. Eugene Sh perhaps implied it was a macro, but what would it be doing in the function definition? Other functions I've seen have, at most, static and a return type.
__devexit is defined in include/linux.h. Make sure you include that header. If you have already done that, make sure you don't have any syntax errors in your code. Also check the previous lines for errors, like eg. a missing semicolon.

error: expected specifier-qualifier-list before

I am getting this following error,
I have a "A.c" file in which I have included a "b.h" file, which has a "c.h" file.
Now this c.h has structures which are getting used and they are all int.
the structures are used in the following way:
In "c.h" file
struct abc{
int a;<---- error
};
In "b.h"
struct def{
struct abc;
};
and I have used struct def in file "A.c" file.
Please, help me know what wrong have I done.
You probably have some nesting error, a missing ; or something that confuses the compiler.
I would recommend trying to get hold of the preprocessor output, so you can see what the compiler sees, once the #includes have been executed.

C compile error

What does the following error mean when compiling.
Tilemap.h:21: error: conflicting types for ‘ThreeDWorld’
Tilemap.h:21: error: previous declaration of ‘ThreeDWorld’ was here
Tilemap.h:29: error: conflicting types for ‘CGPoint’
Tilemap.h:29: error: previous declaration of ‘CGPoint’ was here
Tilemap.h:31: error: conflicting types for ‘tileForCoordinates’
Tilemap.h:31: error: previous declaration of ‘tileForCoordinates’ was here
Why is it giving an error for what was there?My source file has one instance of it as such
typedef struct
{
int xPosition;
int yPosition;
}
CGPoint;
Are you including the header file from more than one place? Use a guard in the header file, if so.
For example, in Tilemap.h:
#ifndef TILEMAP_H
#define TILEMAP_H
// header file contents
#endif /* TILEMAP_H */
Stick some inclusion guards on your headers.
Your type definition is appearing more than once in your compilation unit.
You included the header file twice.
In my own code, I wrapped all header files with
#ifndef HEADER_FILE_NAME
#define HEADER_FILE_NAME
#endif
to avoid such errors.

Passing structs by pointer in C89

I am working with a C89 compiler and I'm coming across some pointer typing error.
Calling code:
struct cpu_state_type cpu_state;
//Stuff here....
foo()
{
print_out_cpu(&cpu_state);
}
Print_out_cpu is defined elsewhere and the H file is #included in.
struct cpu_state_type
{
int r[12];
};
void print_out_cpu(struct cpu_state_type *c);
I get error:
error: incompatible type for argument 1 of 'print_out_cpu'
As best as I can understand,&cpu_state returns type cpu_state_type*, so I am confused.
Are you sure the prototype has the * in it? If I compile (gcc -std=c89) the following code, I get that exact error:
struct cpu_state_type {
int r[12];
};
// note that it is the structure as the param here (not the pointer)
void print_out_cpu(struct cpu_state_type c);
struct cpu_state_type cpu_state;
foo()
{
print_out_cpu(&cpu_state);
}
I don't see any problems, so I wonder if it's an error in your include statement or in the file, etc.
It'll be difficult to determine the cause of the error without seeing more of the source. Try creating a source file like:
#include struct cpu_state_type cpu_state;
void foo() {
print_out_cpu(&cpu_state);
}
If that doesn't trigger the problem, keep adding things until it does.
If it does trigger the problem, extract the pertinent parts of the header file into your source (and remove the #include) and try again.

Resources