470,855 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

C Declarations

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.
Jun 27 '08 #1
1 1089

"Bartc" <bc@freeuk.comwrote in message
news:sm******************@text.news.virginmedia.co m...
>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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Michael Tobis | last post: by
2 posts views Thread by Chris Gordon-Smith | last post: by
134 posts views Thread by James A. Donald | last post: by
14 posts views Thread by Arthur J. O'Dwyer | last post: by
28 posts views Thread by Michael B. | last post: by
1 post views Thread by Chris | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.