ID:2964340
 
BYOND Version:515
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Toyota Corolla AE86
Applies to:ByondAPI
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:

byondapi.h (personally tested v.515.1621, although by Atomix's account 516.1651 doesnt work either) doesnt compile when using a c compiler

Numbered Steps to Reproduce Problem:
1. compile

Code Snippet (if applicable) to Reproduce Problem:
> gcc -x c .\any_use_of_api.c
.\byondapi\byondapi.h:129:8: error: expected identifier or '(' before string constant
129 | extern "C" {
| ^~~


Expected Results:
no breakage

Actual Results:
breakage

Does the problem occur:
Every time? Or how often? yes
In other games? correct
In other user accounts? indeed
On other computers? bacon

When does the problem NOT occur?
after removing the extern "C" binding and extensively tweaking the header file

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
probably not

Workarounds:
use cpp
For further context, the C code is relying on C++ standard. You need to typedef all the unions and structs. [That way it works for both C and C++ without issue]

You should also be using directives to make the code more robust and seamless.

#ifdef __cplusplus
extern "C" {
#endif
/*All da code here*/


#ifdef __cplusplus
}
#endif


You'd also do this at the top where you check to see if c++ is NOT being used, and thus add the header for C files.

Also the last problem is for the "Byond_ThreadSync(ByondCallback callback, void *data, bool block=false)" function.

bool block = false is not valid C syntax. So you'd need two versions, one that is used if you're using c++, or one that adjusts the arguments to work for C. I imagine block would be a pointer to a bool value, and in the function you'd check if block is NULL to set it to the proper value at the top of the function call.

Login to reply.