I am trying to extend Ruby with a C extension in order to add an event hook.
Unfortunately, I get the following error:
timber.c:7: error: expected ‘)’ before ‘event’
timber.c: In function ‘timber_init_event_hook’:
timber.c:15: error: ‘timber_trap’ undeclared (first use in this function)
timber.c:15: error: (Each undeclared identifier is reported only once
timber.c:15: error: for each function it appears in.)
timber.c: At top level:
timber.c:21: error: expected ‘)’ before ‘event’
make: *** [timber.o] Error 1
The code I have written:
#include <ruby.h>
#include </Users/paulengel/.rvm/src/ruby-1.9.2-p180/node.h> // #include <node.h> raises `error: node.h: No such file or directory`
// Declarations
static void timber_init_event_hook();
static void timber_trap(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass);
VALUE timber_start(VALUE self);
void Init_timber();
// Definitions
static void timber_init_event_hook() {
#if defined(RB_EVENT_HOOKS_HAVE_CALLBACK_DATA) || defined(RUBY_EVENT_VM)
rb_add_event_hook(timber_trap, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN, 0);
#else
rb_add_event_hook(timber_trap, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN);
#endif
}
static void timber_trap(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) {
rb_funcall(rb_mKernel, rb_intern("puts"), 1, rb_str_new2(event));
}
VALUE timber_start(VALUE self) {
// Do something
}
void Init_timber() {
VALUE mTimber = rb_define_module("Timber");
timber_init_event_hook();
rb_define_singleton_method(mTimber, "start", timber_start, 0);
}
Can someone help me out solving this problem? Thanks in advance.
EDIT: Try naming your rb_event_t something other than event. Even though I'm almost positive it's not a C keyword, the compile error you're getting seems to be consistent with that type of problem.
EDIT EDIT: Apparently not the actual problem, but it definitely looks like the error is on those two lines.
Related
i've got this error always when i'm using the below code ,
so please could anyone tell me where is my mistake??
the code is:
#ifndef OSAPI_H
#define OSAPI_H
void sdk_os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg);
void sdk_os_timer_arm(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag);
void sdk_os_timer_disarm(ETSTimer *ptimer);
#endif
errors i've got:
1- :4:25: error: unknown type name 'ETSTimer' 2- :4:43: error: unknown
type name 'ETSTimerFunc' 3- :5:23: error: unknown type name 'ETSTimer'
4- :6:26: error: unknown type name 'ETSTimer'
thanks for everyone for the help
I am attempting to compile C files from http://cocoadevcentral.com/articles/000081.php that I literally copy and pasted, so I do not believe there is any type of syntax error, yet I keep getting errors. I do not know what I am doing wrong. I'm using a text editor called TextWrangler to save my write and save my files. I have Xcode downloaded along with its terminal tools so that shouldn't be an issue either.
Here are the errors:
testc4.c:4: error: expected identifier or ‘(’ before ‘)’ token
song.c:5: error: function definition declared ‘typedef’
song.c:5: error: return type is an incomplete type
song.c: In function ‘make_song’:
song.c:6: error: ‘Song’ undeclared (first use in this function)
song.c:6: error: (Each undeclared identifier is reported only once
song.c:6: error: for each function it appears in.)
song.c:6: error: expected ‘;’ before ‘newSong’
song.c:8: error: ‘newSong’ undeclared (first use in this function)
song.c:12: warning: ‘return’ with a value, in function returning void
song.c: At top level:
song.c:15: error: expected ‘)’ before ‘theSong’
Here is the command I'm using to compile my program:
gcc testc4.c song.c -o testc4
If needed I can post the files but they are copied right from the tutorial. I named my test file testc4.c instead of whatever it wanted.
Edit: (I figured you'd need to code)
testc4.c file:
#include <stdio.h>
#include "song.h"
main ()
{
Song firstSong = make_song (210, 2004);
Song secondSong = make_song (256, 1992);
Song thirdSong = { 223, 1997 };
display_song ( thirdSong );
Song fourthSong = { 199, 2003 };
}
song.c file:
#include <stdio.h>
#include "song.h"
Song make_song (int seconds, int year)
{
Song newSong;
newSong.lengthInSeconds = seconds;
newSong.yearRecorded = year;
display_song (newSong);
return newSong;
}
void display_song (Song theSong)
{
printf ("the song is %i seconds long ", theSong.lengthInSeconds);
printf ("and was made in %i\n", theSong.yearRecorded);
}
song.h file
typedef struct {
int lengthInSeconds;
int yearRecorded;
} Song;
Song make_song (int seconds, int year);
void display_song (Song theSong);
These are straight copied from the site. I typed them out first but when it didn't work I copy and pasted them.
Probably you just have to change:
main ()
to
void main ()
I can't find what is wrong with my code in C:
error.h
#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED
void myfunc(bool**,int); //error line 1
#endif
Here is the function declaration:
error.c
#include "error.h"
void myfunc(bool **rel,int num){ //error line 2
//function code here
}
The call of the function is :
main.c
#include "error.h"
int main(){
bool **rel;
int num;
myfunc(rel,num);
return 0;
}
The above code returns the error
expected ')' before '*' token
at the error line 1 and error line 2.I put the function code in comments and i still have this error.I know that, that kind of error is a missing ; or ) at the most times but i spend hours and didn't find the error.
bool type is not recognized, you need to include stdbool.h in your error.h header.
The following code (a function prototype):
void parse_ini(FSFILE *fp, void(*secFunc)(char*), void(*varFunc)(char*, char*));
presents errors when compiled:
util\setup.c:38: error: syntax error before '*' token
util\setup.c:38: error: 'parse_ini' declared as function returning a function
util\setup.c:38: error: syntax error before 'void'
util\setup.c:50: error: syntax error before '*' token
What is causing this? Using MPLAB C30, which is a version of GCC v3.23 for PIC24F/dsPIC 16-bit microcontrollers.
I'd guess that you haven't included a header that declares/defines FSFILE.
try this
typedef void (*varfuncptr)(char *, char*);
typedef void (*secfuncptr)(char *);
void parse_ini(FSFILE *fp, secfuncptr *secFunc, varfuncptr *varFunc);
I have a C header file which defines the following function:
void my_func(pthread_t tid);
This is defined by another function:
void my_func(pthread_t tid) {
...
When I compile, it says:
****.h:2: error: expected specifier-qualifier-list before ‘pthread_t’
Any ideas what I'm doing wrong?
You need to #include <pthread.h> in the header file so that pthread_t is in scope for the my_func() prototype.
Without the #include the compiler does not recognize pthread_t as a type, but it needs a type before the argument.
The error expected specifier-qualifier-list before ‘pthread_t’ is saying just that. You need a type (specifier-qualifier-list) before a parameter (‘pthread_t’).