C Declarations

Discussion in 'C Programming' started by Bartc, May 4, 2008.

  1. Bartc

    Bartc Guest

    I need to be able generate C-style declarations from a specification (I call
    it a typespec) in left-to-right form (as it might be expressed in English).

    What is the algorithm, or where can I found the algorithm, to do so?

    I have looked at some code in K&R2 p126 ('undcl'), but that works on
    character input (I already have the typespec in internal form).

    And I've heard of something called cdecl.c but that seems to be 2000 lines +
    headers which I'm not keen to delve into; I expect the code to be very
    simple, once I know it..

    Simple Examples:

    Input Outputs (with and without embedded name)

    'Array 3 of int' int x[3] int[3]

    'Pointer to char' char *x char*

    But this needs to work with arbitrary typespecs.

    --
    Thanks,

    Bartc.
    Bartc, May 4, 2008
    #1
    1. Advertising

  2. Bartc

    Bartc Guest

    "Bartc" <> wrote in message
    news:smoTj.19778$...
    >I need to be able generate C-style declarations from a specification (I
    >call it a typespec) in left-to-right form (as it might be expressed in
    >English).
    >
    > What is the algorithm, or where can I found the algorithm, to do so?


    Never mind, I managed to sort something out by trial and error: generating
    some combination of *, (, ), [ and ] and using cdecl to see if this
    corresponded to my input. Probably too many (,) in there but they don't
    hurt.

    --
    Bartc
    Bartc, May 5, 2008
    #2
    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. deep
    Replies:
    0
    Views:
    480
  2. M.D. van de Burgwal
    Replies:
    3
    Views:
    1,079
    Paul Uiterlinden
    Oct 7, 2004
  3. =?ISO-8859-1?Q?Andr=E9s?=

    Pin declarations in EC/ECP FPGAs

    =?ISO-8859-1?Q?Andr=E9s?=, Feb 22, 2005, in forum: VHDL
    Replies:
    11
    Views:
    2,501
    cristian
    Mar 11, 2005
  4. Srinivasan Venkataramanan

    Do you still use component declarations?

    Srinivasan Venkataramanan, Sep 18, 2005, in forum: VHDL
    Replies:
    3
    Views:
    665
    Colin Marquardt
    Sep 19, 2005
  5. Replies:
    0
    Views:
    303
Loading...

Share This Page