473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1992
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DJ | last post by:
Here are my answers for quiz 3 - how well did I do? 1. If the statement: scanf("%d %d", &N1, &N2); returns the value 1, what do we know about what was read into the variables N1 and N2?
2
by: Sketcher | last post by:
Hi, I am trying to create a quiz, Code is as follows: <html> <head> <title>Quiz</title> </head> <BODY> <Center><TABLE cellSpacing=3 cellPadding=0 border=0>
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
6
by: shror | last post by:
hi every body, i have a problem dealing with a quiz system in php. the idea is that am building a quiz system by giving a question and choices in radio buttons, and after selecting the answer...
1
by: gts | last post by:
Hi, I've put together a little quiz using javascript. It doesn't actually keep score, it let's you keep answering the same question until you get it right. Most of the questions use multiple choice...
12
by: lkrzysiak | last post by:
I was traing to figure out an expression finding table names in sql query. Table name is known, for example 'table'. Below is sample code. This code should find last four strings ONLY. Other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.