470,866 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

A little quiz on macros

How would you implement a static dictionary with macros?

For example, the five lines

PL_FIND(MYDICT, HOUSE)
PL_FIND(MYDICT, AUTO)
PL_FIND(MYDICT, THIS_IS_NOT_IN_THE_DICTIONARY)
PL_FIND(MYDICT, jhgjhguytuyhkgjhg)
PL_FIND(MYDICT, 3498fjkhdlkh34098jhf)

should produce:

house_definition
auto_definition
symbol_not_found
symbol_not_found
symbol_not_found

Kiuhnm
May 10 '06 #1
13 1833
Kiuhnm <"kiuhnm03["@]yahoo.it> wrote:
How would you implement a static dictionary with macros?


I wouldn't. Learning stupid preprocessor tricks is a recipe for
disaster; you _will_ use them in production code, and that _will_ go
creatively and headache-inducingly wrong.

Next!

Richard
May 10 '06 #2
Richard Bos ha scritto:
I wouldn't. Learning stupid preprocessor tricks is a recipe for
disaster; you _will_ use them in production code, and that _will_ go
creatively and headache-inducingly wrong.


The C language is a trick. The C++ language is a trick. The assembly
language is a trick. A lever is a trick. What we see is a trick. And
then what? Should we limit our curiosity and creativity? I don't think so.
A little quiz is a little quiz, not a recipe for building strong
industrial applications. Anyway I was quite sure there was a standard
describing the C preprocessor.

Kiuhnm
May 10 '06 #3
On 2006-05-10, Kiuhnm <"kiuhnm03["@> wrote:
Richard Bos ha scritto:
I wouldn't. Learning stupid preprocessor tricks is a recipe for
disaster; you _will_ use them in production code, and that _will_ go
creatively and headache-inducingly wrong.


The C language is a trick. The C++ language is a trick. The assembly
language is a trick. A lever is a trick. What we see is a trick.


Sure they are. The difference is they're not stupid.
May 10 '06 #4
Jordan Abel ha scritto:
Sure they are. The difference is they're not stupid.


Then you must have solved the quiz and found it stupid.
Would you be so kind as to give me your answer?
I am very interested.

Kiuhnm
May 10 '06 #5
On Wed, 10 May 2006 20:28:08 +0200, Kiuhnm <"kiuhnm03["@]yahoo.it>
wrote:
Jordan Abel ha scritto:
Sure they are. The difference is they're not stupid.
Then you must have solved the quiz and found it stupid.


That doesn't follow. Here's the solution to your "quiz", repeated
here:

Quiz:How would you implement a static dictionary with macros?

Answer: I wouldn't.
Would you be so kind as to give me your answer?
I am very interested.

Kiuhnm


--
Al Balmer
Sun City, AZ
May 10 '06 #6
On 2006-05-10, Kiuhnm <"kiuhnm03["@> wrote:
Jordan Abel ha scritto:
Sure they are. The difference is they're not stupid.


Then you must have solved the quiz and found it stupid.
Would you be so kind as to give me your answer?
I am very interested.


I believe there is not an answer which would allow the "unknownsymbol"
responses. If there is, it requires excessively stupid contortions.
May 10 '06 #7
Al Balmer ha scritto:
Quiz:How would you implement a static dictionary with macros?

Answer: I wouldn't.


Wrong answer. Maybe you missed the word "How".

Kiuhnm
May 10 '06 #8
Jordan Abel ha scritto:
I believe there is not an answer which would allow the "unknownsymbol"
responses. If there is, it requires excessively stupid contortions.


Yep, very logical.

Kiuhnm
May 10 '06 #9
Kiuhnm <"kiuhnm03["@]yahoo.it> wrote:
Quiz:How would you implement a static dictionary with macros?

Answer: I wouldn't.
Wrong answer. Maybe you missed the word "How".


You missed the implied point that whomever is asking this question -
be it an instructor, a recruiter, or your boss - is either
intentionally wasting your time or an idiot, probably both. See what
your answer becomes when you unwittingly accept a job *maintaining*
this macro-implemented static dictionary.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
May 11 '06 #10
Christopher Benson-Manica ha scritto:
You missed the implied point that whomever is asking this question -
be it an instructor, a recruiter, or your boss - is either
intentionally wasting your time or an idiot, probably both. See what
your answer becomes when you unwittingly accept a job *maintaining*
this macro-implemented static dictionary.


You missed the implied point that this is a "little quiz on macros". You
guys are surprising: you don't know the answer and still say the
solution is stupid and/or unmaintainable.
Your behavior is simply unacceptable. Farewell.

Kiuhnm
May 11 '06 #11
On 2006-05-11, Kiuhnm <"kiuhnm03["@> wrote:
Christopher Benson-Manica ha scritto:
You missed the implied point that whomever is asking this question -
be it an instructor, a recruiter, or your boss - is either
intentionally wasting your time or an idiot, probably both. See what
your answer becomes when you unwittingly accept a job *maintaining*
this macro-implemented static dictionary.


You missed the implied point that this is a "little quiz on macros". You
guys are surprising: you don't know the answer and still say the
solution is stupid and/or unmaintainable.
Your behavior is simply unacceptable. Farewell.


OK - here's my answer.

A solution is impossible. The closest would be to define each valid key
with a prefix, and use the ## operator - but that wouldn't allow the
symbol_not_found.

This is beyond the capabilities of the c preprocessor language.
May 11 '06 #12
Kiuhnm <"kiuhnm03["@]yahoo.it> wrote:
Christopher Benson-Manica ha scritto:
You missed the implied point that whomever is asking this question -
be it an instructor, a recruiter, or your boss - is either
intentionally wasting your time or an idiot, probably both. See what
your answer becomes when you unwittingly accept a job *maintaining*
this macro-implemented static dictionary.
You missed the implied point that this is a "little quiz on macros". You
guys are surprising: you don't know the answer and still say the
solution is stupid and/or unmaintainable.


No. The _question_ is stupid. Yes, even as a "little quiz" on macros.
It's like asking "How would you build a two-story house out of balsa
wood?" Sure, there's probably an answer. Sure, there's possibly even a
very clever answer that would be marginally livable-in. But it's still a
stupid question, nobody sane is going to want to live in the result, and
no serious architect is going to ponder the question for more than three
seconds.
Your behavior is simply unacceptable.


And who are you to decide this?

Richard
May 11 '06 #13
Christopher Benson-Manica wrote:

You missed the implied point that whomever is asking this question -


Should be 'whoever'. (Not normally a grammar nazi, but I hate
it when people try to be correct and get it wrong, instead of
just speaking naturally).

May 12 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by DJ | last post: by
2 posts views Thread by Sketcher | last post: by
4 posts views Thread by DAL | last post: by
6 posts views Thread by shror | last post: by
12 posts views Thread by lkrzysiak | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.