Does ruby.h overrides C "enum"?

Discussion in 'Ruby' started by Iñaki Baz Castillo, Oct 12, 2009.

  1. 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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #1
    1. Advertising

  2. Iñaki Baz Castillo

    Tim Hunter Guest

    Iñaki Baz Castillo wrote:
    > 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.

    --
    Posted via http://www.ruby-forum.com/.
    Tim Hunter, Oct 12, 2009
    #2
    1. Advertising

  3. Iñaki Baz Castillo

    7stud -- Guest

    Iñaki Baz Castillo wrote:
    > 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’

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 12, 2009
    #3
  4. El Lunes, 12 de Octubre de 2009, Tim Hunter escribi=C3=B3:
    > I=C3=B1aki Baz Castillo wrote:
    > > 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 =E2=80=98(=E2=80=99 token
    > >
    > >
    > > It doesn't occur if I quit "ruby.h". What is happening?
    > >
    > > Thanks.

    >=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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #4
  5. El Lunes, 12 de Octubre de 2009, 7stud -- escribi=C3=B3:
    > I=C3=B1aki Baz Castillo wrote:
    > > 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 =E2=80=98(=E2=80=99 token
    > >
    > >
    > > It doesn't occur if I quit "ruby.h". What is happening?

    >=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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #5
  6. 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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #6
  7. Iñaki Baz Castillo

    angico Guest

    Hi,

    =2D-----
    On Monday 12 October 2009 11:17:08 I=C3=B1aki Baz Castillo wrote:
    > 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":
    > >
    > > #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?

    >
    > 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:
    skype: angico00
    angico, Oct 12, 2009
    #7
  8. 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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #8
  9. 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

    On Oct 12, 2009, at 10:52 AM, I=F1aki Baz Castillo wrote:

    > El Lunes, 12 de Octubre de 2009, angico escribi=F3:
    >> Are you sure the typo was only in the mail? If I copy and paste =20
    >> this code
    >> in a file and try to compile it, the compiler complains about the =20=


    >> same
    >> error, because void is a reserved keyword in C. But when I change =20
    >> that
    >> "void(void)" into "main(void)" it compiles ok.

    >
    > 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 <>
    >


    Rob Biedenharn http://agileconsultingllc.com
    Rob Biedenharn, Oct 12, 2009
    #9
  10. 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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #10
  11. Iñaki Baz Castillo

    angico Guest

    =2D-----
    On Monday 12 October 2009 12:23:24 Rob Biedenharn wrote:
    > 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:
    skype: angico00
    angico, Oct 12, 2009
    #11
  12. Iñaki Baz Castillo

    7stud -- Guest

    Iñaki Baz Castillo wrote:
    > El Lunes, 12 de Octubre de 2009, 7stud -- escribió:
    >> > 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"?

    >
    > I just mean that the above code (note that it should be "int
    > main(void)")
    > without '#include "ruby.h"' line compiles ok.
    >
    >
    >> What compiler are you using?

    >
    > gcc 4.3 under Debian Lenny 64 bits.
    >
    >
    >> 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’

    >
    > 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.
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 12, 2009
    #12
  13. 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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #13
  14. Iñaki Baz Castillo

    Seebs Guest

    On 2009-10-12, Iñaki Baz Castillo <> wrote:
    > ----------------
    > #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
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Oct 12, 2009
    #14
  15. Iñaki Baz Castillo

    Seebs Guest

    On 2009-10-12, Iñaki Baz Castillo <> wrote:
    > 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
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Oct 12, 2009
    #15
  16. Iñaki Baz Castillo

    Paul Smith Guest

    On Mon, Oct 12, 2009 at 7:25 PM, Seebs <> wrote:
    > On 2009-10-12, I=F1aki Baz Castillo <> wrote:
    >> 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. =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

    Paul Smith, Oct 12, 2009
    #16
  17. Iñaki Baz Castillo

    Seebs Guest

    On 2009-10-12, Paul Smith <> wrote:
    > 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
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Oct 12, 2009
    #17
  18. El Lunes, 12 de Octubre de 2009, Paul Smith escribi=F3:
    > On Mon, Oct 12, 2009 at 7:25 PM, Seebs <> wrote:
    > > On 2009-10-12, I=F1aki Baz Castillo <> wrote:
    > >> 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.

    >=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 <>
    Iñaki Baz Castillo, Oct 12, 2009
    #18
  19. Iñaki Baz Castillo

    Seebs Guest

    On 2009-10-12, Iñaki Baz Castillo <> wrote:
    > 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
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Oct 12, 2009
    #19
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    515
  2. Jerminia
    Replies:
    3
    Views:
    607
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    435
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    392
    Dave Thompson
    Jun 10, 2004
  5. Randy
    Replies:
    1
    Views:
    506
    David Harmon
    Jan 7, 2006
Loading...

Share This Page