Why does this static funtion have three prefixes? - c

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.

Related

Undeclared identifier with definition in header file

include "spinach.h" is included in the main.c file
main.c makes a function call to a struct defined in spinach.h header. The function call occurs in the main.c function, and is the first reference to this type Lexer. The main.c file runs without error absent this line.
Lexer *lex = malloc(sizeof(Lexer));
The definition is on the 0 indentation level (it is not defined in local scope); it is given below in triple quotes. In the header (spinach.h)
typedef struct {
char **lines;
char* current;
int pos;
int line;
int col;
int* indentlevel;
int indentcap;
int indentlen;
} Lexer;
What happpens?
 bash run.sh
main.c:115:3: error: use of undeclared identifier 'Lexer'
Lexer *lex;
^
main.c:115:10: error: use of undeclared identifier 'lex'
Lexer *lex;
^
2 errors generated.
Any variation that includes Lexer, including using pointers, references to malloc or the output of a custom initializer function will throw related errors.
Looked for multiple references (same global variable in 2 files in main.py references) to Lexer. All references on the internet are examples wherein the header file is not included, the variable or function is defined after the reference or call, or is absent entirely, else the error will show where there shows a reference in a global scope to a local definition. I do not see this to be the case. All references to custom struct lever in the main.c file, main function will throw this error. If the definitions are placed in the main.c file itself, instead of the header spinach.h referenced, it runs without error.

libwebsockets: Dereferencing pointer to incomplete type error

I'm using libwebsockets and I can't compile a demo code implemented by myself.
I created the context:
struct libwebsocket_context *context;
...
context = libwebsocket_create_context(&info);
and when I try to access the members of the struct libwebsocket_context, defined in private-libwebsockets.h:
struct libwebsocket_context {
struct pollfd *fds;
struct libwebsocket **lws_lookup; /* fd to wsi */
int fds_count;
int max_fds;
int listen_port;
...
};
For example,
printf("%d\n", context->listen_port);
The compiler returns,
error: dereferencing pointer to incomplete type
Thanks!
It seems that "struct libwebsocket_context" is not known for gcc - that's why this error occures. Are you sure that definition of this structure is included from .h file? I'd suggest you to insert for example #warning or #error with some message near definition of this struct (in .h file) and try to recompile your program. Your #error or #warning message should appear while compilation. If not - it means that gcc will not also see this struct.
The fact that the struct definition is in private-libwebsockets.h suggests that you are not supposed to use the struct members directly. You can #include that header to get access to the private implementation details of the library but you probably should not do it.

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

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

No warning or error indication when variable defined as static but declared as extern

I came across some code today that surprised me. A variable was defined (outside of a function) in the .c file as being static. However, in the .h file it was declared as being extern. Here is a similar example of the code:
Structure definitions and declaration in .h:
typedef struct
{
unsigned char counter;
unsigned char some_num;
} One_Struct;
typedef struct
{
unsigned char counter;
unsigned char some_num;
const unsigned char * p_something;
} Another_Struct;
typedef struct
{
One_Struct * const p_one_struct;
Another_Struct * const p_another_struct;
} One_Useful_Struct;
extern One_Useful_Struct * const p_my_useful_struct[];
Definition and initialization in .c:
static One_Useful_Struct * const p_my_useful_struct[MAX_USEFUL_STRUCTS] =
{
&p_my_useful_struct_regarding_x,
&p_my_useful_struct_regarding_y,
};
Question:
So my question is, why didn't I receive a compiler error or warning?
The code has been successfully running in other projects for some time now. I did note that the pointer is never used outside of the .c file in which it is defined and was properly defined as static (I removed the external declaration). The only reason that I found it was because I ran Lint on the project and Lint picked it up.
It's certianly not standard C. GCC and clang both detect and give an error on this case:
$ gcc example.c
example.c:4: error: static declaration of ‘x’ follows non-static declaration
example.c:3: error: previous declaration of ‘x’ was here
$ clang example.c
example.c:4:12: error: static declaration of 'x' follows non-static declaration
static int x;
^
example.c:3:12: note: previous definition is here
extern int x;
^
1 error generated.
You must be using a pretty permissive compiler - maybe Visual Studio? I just checked on my Windows machine and VS2003 accepts my example program silently. Adding /Wall does give a warning:
> cl /nologo /Wall example.c
example.c
example.c(4) : warning C4211: nonstandard extension used : redefined extern to static
Looks to me like you're using an extension of whatever compiler it is that you're using.

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