A little quiz on macros

K

Kiuhnm

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
 
R

Richard Bos

Kiuhnm said:
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
 
K

Kiuhnm

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
 
J

Jordan Abel

Richard Bos ha scritto:

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

Kiuhnm

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
 
A

Al Balmer

Jordan Abel ha scritto:

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

Jordan Abel

Jordan Abel ha scritto:

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

Kiuhnm

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
 
K

Kiuhnm

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
 
C

Christopher Benson-Manica

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

Kiuhnm

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
 
J

Jordan Abel

Christopher Benson-Manica ha scritto:

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

Richard Bos

Kiuhnm said:
Christopher Benson-Manica ha scritto:

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
 
O

Old Wolf

Christopher said:
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).
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,517
Latest member
TashaLzw39

Latest Threads

Top