Does ruby.h overrides C "enum"?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, writting a Ruby C extension (for 1.8 or 1.9) I get an error when using=
=20
"enum":

#include "ruby.h"
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}

line 3: error: expected identifier before =E2=80=98(=E2=80=99 token


It doesn't occur if I quit "ruby.h". What is happening?

Thanks.



=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
T

Tim Hunter

Iñaki Baz Castillo said:
Hi, writting a Ruby C extension (for 1.8 or 1.9) I get an error when
using
"enum":

#include "ruby.h"
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}

line 3: error: expected identifier before ‘(’ token


It doesn't occur if I quit "ruby.h". What is happening?

Thanks.

I think the compiler is complaining about your attempt to use "void" as
a function name. "void" is a reserved word in C.
 
7

7stud --

Iñaki Baz Castillo said:
Hi, writting a Ruby C extension (for 1.8 or 1.9) I get an error when
using
"enum":

#include "ruby.h"
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}

line 3: error: expected identifier before ‘(’ token


It doesn't occur if I quit "ruby.h". What is happening?

What does "quit ruby.h mean"? What compiler are you using?

test.c :
-----
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}


--output:--
$ g++ test.c -o test
test.c:1: error: expected unqualified-id before ‘void’
test.c:1: error: expected `)' before ‘void’
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, Tim Hunter escribi=C3=B3:
=20
I think the compiler is complaining about your attempt to use "void" as
a function name. "void" is a reserved word in C.

No no, that's a typo of mie when composing the mail.
Imagine it's "int main(void)".=20


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, 7stud -- escribi=C3=B3:
=20
What does "quit ruby.h mean"?

I just mean that the above code (note that it should be "int main(void)")=20
without '#include "ruby.h"' line compiles ok.

What compiler are you using?

gcc 4.3 under Debian Lenny 64 bits.

=20
test.c :
-----
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}
=20
=20
--output:--
$ g++ test.c -o test
test.c:1: error: expected unqualified-id before =E2=80=98void=E2=80=99

Yes, a typo of my mail. Please use "int main(void)" instead.




=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
Hi, writting a Ruby C extension (for 1.8 or 1.9) I get an error when using
"enum":
=20
#include "ruby.h"
int void(void) {
enum kk {ONE, TWO, THREE}; // line 3
}
=20
line 3: error: expected identifier before =E2=80=98(=E2=80=99 token
=20
=20
It doesn't occur if I quit "ruby.h". What is happening?


opss, the same error occurs if I add "#include <stdio.h>".

=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
A

angico

Hi,

=2D-----
El Lunes, 12 de Octubre de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:

opss, the same error occurs if I add "#include <stdio.h>".

Are you sure the typo was only in the mail? If I copy and paste this code i=
n a=20
file and try to compile it, the compiler complains about the same error,=20
because void is a reserved keyword in C. But when I change that "void(void)=
"=20
into "main(void)" it compiles ok.


=2D-=20
angico
=2D-----

Site: angico.org
Blog: angico.org/blog

Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I

=3D=3D Coopera=C3=A7=C3=A3o =C3=A9 _muito_ melhor que competi=C3=A7=C3=A3o =
=3D=3D

=2D-----
contatos:
email: (e-mail address removed)
skype: angico00
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, angico escribi=C3=B3:
Are you sure the typo was only in the mail? If I copy and paste this code
in a file and try to compile it, the compiler complains about the same
error, because void is a reserved keyword in C. But when I change that
"void(void)" into "main(void)" it compiles ok.

ok, let's try it:

file_a.c
=2D---------------
int main(void) {
enum kk {NULL=3D0, NS=3D1, URL=3D2};
}
=2D---------------

It compiles ok.


Now:

file_b.c
=2D---------------
#include <stdio.h>
int main(void) {
enum kk {NULL=3D0, NS=3D1, URL=3D2};
}
=2D---------------

$ gcc file_b.c
file_b.c: In function =E2=80=98main=E2=80=99:
file_b.c:3: error: expected identifier before =E2=80=98(=E2=80=99 token



=C2=BF?=C2=BF?

PS: It seems to be a problem not related to Ruby.

=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
R

Rob Biedenharn

I think you'll find your problem is due to a macro for NULL.
Change your code from "NULL" to "kNULL":

#include <stdio.h>
int main(void) {
enum kk {kNULL=3D0, NS=3D1, URL=3D2};
}

and your problem goes away.

-Rob

El Lunes, 12 de Octubre de 2009, angico escribi=F3:

ok, let's try it:

file_a.c
----------------
int main(void) {
enum kk {NULL=3D0, NS=3D1, URL=3D2};
}
----------------

It compiles ok.


Now:

file_b.c
----------------
#include <stdio.h>
int main(void) {
enum kk {NULL=3D0, NS=3D1, URL=3D2};
}
----------------

$ gcc file_b.c
file_b.c: In function =91main=92:
file_b.c:3: error: expected identifier before =91(=92 token



=BF?=BF?

PS: It seems to be a problem not related to Ruby.

--=20
I=F1aki Baz Castillo <[email protected]>

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, Rob Biedenharn escribi=F3:
I think you'll find your problem is due to a macro for NULL.
Change your code from "NULL" to "kNULL":
=20
#include <stdio.h>
int main(void) {
enum kk {kNULL=3D0, NS=3D1, URL=3D2};
}
=20
and your problem goes away.

opss, great!

Thanks a lot.

=2D-=20
I=F1aki Baz Castillo <[email protected]>
 
A

angico

=2D-----
I think you'll find your problem is due to a macro for NULL.
Change your code from "NULL" to "kNULL":

#include <stdio.h>
int main(void) {
enum kk {kNULL=3D0, NS=3D1, URL=3D2};
}

and your problem goes away.

-Rob

Yeah! That makes a big difference, since in the original post it was
"enum kk {ONE, TWO, THREE};"

=2D-=20
angico
=2D-----

Site: angico.org
Blog: angico.org/blog

Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I

=3D=3D Coopera=E7=E3o =E9 _muito_ melhor que competi=E7=E3o =3D=3D

=2D-----
contatos:
email: (e-mail address removed)
skype: angico00
 
7

7stud --

Iñaki Baz Castillo said:
El Lunes, 12 de Octubre de 2009, 7stud -- escribió:

I just mean that the above code (note that it should be "int
main(void)")
without '#include "ruby.h"' line compiles ok.



gcc 4.3 under Debian Lenny 64 bits.



Yes, a typo of my mail. Please use "int main(void)" instead.


Maybe next time you should consider posting the code that actually
produced the error message. Debugging fake programs never works very
well.
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, 7stud -- escribi=C3=B3:
Maybe next time you should consider posting the code that actually
produced the error message. Debugging fake programs never works very
well.

Right, I'm sorry. I never spected that the usage of "NULL" was creating the=
=20
issue.

Thanks a lot.=20


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
S

Seebs

----------------
#include <stdio.h>
int main(void) {
enum kk {NULL=0, NS=1, URL=2};
}

NULL is a symbol defined by the implementation, and defined by several of
the standard headers (including <stdio.h>).

Usually, it is either "0" or "(void *) 0" or something equivalent.
$ gcc file_b.c
file_b.c: In function ?main?:
file_b.c:3: error: expected identifier before ?(? token

I'd bet you've got one where it's "(void *) 0".

-s
 
S

Seebs

Right, I'm sorry. I never spected that the usage of "NULL" was creating the
issue.

The secret to effective debugging:

If you suspected what it was, you wouldn't need to ask for help. So it
is usually best to try to include a tested reproducer rather than guessing
at which parts are relevant.

This is something that takes people a few tries to get, usually.

-s
 
P

Paul Smith

The secret to effective debugging:

If you suspected what it was, you wouldn't need to ask for help. =A0So it
is usually best to try to include a tested reproducer rather than guessin= g
at which parts are relevant.

At least, mocking up an example is fine, but check that the mocked up
example demonstrates the same failure. In this case, your mocked up
example did not, and having seen that, you would likely have solved
the problem yourself :)
--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 
S

Seebs

At least, mocking up an example is fine, but check that the mocked up
example demonstrates the same failure. In this case, your mocked up
example did not, and having seen that, you would likely have solved
the problem yourself :)

Yes. And be sure the mockup is actually representing the problem as such...

My favorite example of recent memory: Someone reported a bug, which
was that the compiler was generating an instruction not supported by a
particular CPU. The submitted reproducer, to simplify things, simply
included the unwanted instruction in inline assembly... It took some
prodding to discover that there was an actual, underlying, problem.

-s
 
I

Iñaki Baz Castillo

El Lunes, 12 de Octubre de 2009, Paul Smith escribi=F3:
=20
At least, mocking up an example is fine, but check that the mocked up
example demonstrates the same failure. In this case, your mocked up
example did not, and having seen that, you would likely have solved
the problem yourself :)

100% agree. I'm really sorry the waste of time.

Thanks a lot.=20


=2D-=20
I=F1aki Baz Castillo <[email protected]>
 
S

Seebs

100% agree. I'm really sorry the waste of time.

Don't sweat it. You learned something.

I don't participate in Usenet because I want the answers I give to the
specific questions people asked to be the most efficient possible use of
anyone's time; I participate in Usenet because I want to learn things and
help other people learn things.

If you learned something about debugging, and something about asking
questions, that's great. It doesn't have to always be exactly the thing
you thought you were going to learn...

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top