简体   繁体   中英

SYNTAX: what is the correct way to do a forward declaration for a c function?

I am currently tasked with getting code from one device to run on another and have a snippet of the functionality which means I need to shut down or feed the interfaces that are not being fed due to the cutting out of this module. When trying to compile I'm running into a syntax error that baffles me.

In a .h file I found a forward declaration at global scope like this:

void INT_CODE_ATTR fatal_error (unsigned char error_module, unsigned short error_line);

Where INT_CODE_ATTR was not defined. Since I don't know what it could/should be I did this:

#define INT_CODE_ATTR
void INT_CODE_ATTR fatal_error (unsigned char error_module, unsigned short error_line);

This gave me the error:

error: declaration does not declare anything [-fpermissive]

So I changed ; to {} resulting in this error:

error: expected unqualified-id before '{' token

I thought it had to have something to do with INT_CODE_ATTR so I commented it out, but the error persists. Also the whole line is underlined (in Eclipse) and it tells me just: "Syntax Error".

Just to clarify, my last attempt at solving this looked like this:

#define INT_CODE_ATTR
void /*INT_CODE_ATTR*/ fatal_error (unsigned char error_module, unsigned short error_line) {}

The code sniplet you gave works just fine. Nothing wrong there (once you defined INT_CODE_ATTR).

Run gcc -E or your compilers equivalent to see what the pre-processor makes out of your actual code. What the actual compiler gets is not what you wrote, something is messing up the input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM