Friday, April 8, 2016

Digest for comp.lang.c++@googlegroups.com - 18 updates in 5 topics

Christian Gollwitzer <auriocus@gmx.de>: Apr 08 01:24PM +0200

Hello,
 
is it possible to stringify a list of arguments in a preprocessor macro?
 
Background: I'm interfacing with a C library, which expects two parallel
arrays, one with C strings, one with function pointers. I'd like to be
able to pass only a the list of functions to the macro. So I'd like to have
 
TABLE(add, subtract, multiply)
 
generate this code
 
const char * text[] = { "add", "subtract", "multiply", NULL };
void * fun[] = { add, subtract, multiply };
 
 
Christian
Ondra Holub <ondra.holub@post.cz>: Apr 08 09:22AM -0700

Something like that:
 
#define ITEMS ITEM(add), ITEM(sub), ITEM(mul), ITEM(div)
 
#define ITEM ITEM_AS_STRING
const char* text[] = { ITEMS, NULL };
#undef I
 
#define I ITEM_AS_IS
void* fun[] = { ITEMS };
#undef I
 
Yes, it is ugly. You can move some stuff to included file, so it would look like:
 
#define ITEMS ITEM(add), ITEM(sub), ITEM(mul), ITEM(div)
#include "generate"
 
Which is "a bit" better.
 
Anyway, I would suggest to use one array of struct:
 
#define ITEM(item) { #item, item }
 
struct XY
{
const char* text;
void* fun;
}
xy[] =
{
ITEM(add),
ITEM(sub),
ITEM(mul),
ITEM(div)
};
Marcel Mueller <news.5.maazl@spamgourmet.org>: Apr 08 06:26PM +0200

On 08.04.16 13.24, Christian Gollwitzer wrote:
 
> generate this code
 
> const char * text[] = { "add", "subtract", "multiply", NULL };
> void * fun[] = { add, subtract, multiply };
 
#define TABLE(p1, p2, p3) \
const char* text[] = { #p1, #p2, #p3 }; \
void* fun[] = { p1, p2, p3 }
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Apr 08 06:28PM +0200

On 08.04.2016 13:24, Christian Gollwitzer wrote:
 
> generate this code
 
> const char * text[] = { "add", "subtract", "multiply", NULL };
> void * fun[] = { add, subtract, multiply };
 
You can start by defining
 
TABLE( ... ) \
const char* text[] = { FUNC_NAME_LIST( __VA_ARGS__ ) nullptr }; \
Func_type fun[] = { __VA_ARGS__ };
 
Now the problem is reduced to defining FUNC_NAME_LIST.
 
:)
 
 
All approaches I've seen are based on counting the number of macro
arguments, which can be done using a technique posted in comp.std.c
(IIRC) around 1999. That number can then be concatenated with a macro
name. Which can be a general macro that lets you invoke a specified
macro for each argument.
 
However, eespecially the Visual C++ compiler is problematic, because it
has its own ideas about how preprocessor symbol concatenation should work.
 
I think the Boost Preprocessor library supplies this functionality in a
portable way, as a macro FOR_EACH or similarly named, with workarounds
for various compilers.
 
 
Cheers & hth.,
 
- Alf
Melzzzzz <mel@zzzzz.com>: Apr 08 09:11PM +0200

On Fri, 8 Apr 2016 13:24:19 +0200
 
> const char * text[] = { "add", "subtract", "multiply", NULL };
> void * fun[] = { add, subtract, multiply };
 
> Christian
 
Try D. It is easy in D....
Christian Gollwitzer <auriocus@gmx.de>: Apr 08 09:46PM +0200

Am 08.04.16 um 13:24 schrieb Christian Gollwitzer:
> is it possible to stringify a list of arguments in a preprocessor macro?
 
Thanks to all for your ideas. Indeed Boost does have a solution,
unfortunately with an ugly call syntax. Finally I found a small library
via stackoverflow. It's here:
 
https://github.com/swansontec/map-macro
 
Short & sweet :)
 
It's really a shame that preprocessor is such a crippled language.
 
 
Christian
Jerry Stuckle <jstucklex@attglobal.net>: Apr 07 08:02PM -0400

On 4/7/2016 6:29 AM, Vlad from Moscow wrote:
>> things, so you should figure it out for yourself. Otherwise you won't
>> learn anything (similar to just giving someone their homework answer).
 
> It is such a bad joke?:)
 
Not a bad joke. Just pointing out you are not as right as you think you
are. Can't you figure out what you did wrong?
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Apr 07 08:04PM -0400

On 4/7/2016 6:34 AM, Vlad from Moscow wrote:
 
> "I know what's incorrect - as I suspect do the people who downvoted you.
> And insisting incorrect code is correct is a good reason for banning. "
 
> What is better "to suspect" or to write in a comment what is wrong with the code?:) It looks like "I am so smart that I wil say never what is wrong":)
 
No, it's a matter if you don't try to figure out what's wrong, you will
never learn.
 
Just like doing other peoples' homework for them (especially without any
explanation) won't help them learn.
 
And no, you aren't going to goad me into telling you what your problems
are. You're so smart, you should be able to figure them out for yourself.
 
But one thing to remember - quantity does NOT equal quality. Just
because you posted a lot does NOT mean your posts were any good - or
that you know what you're talking about. Here's your chance to prove
you DO know what you're talking about.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Apr 07 08:06PM -0400

On 4/7/2016 8:45 AM, Chris Vine wrote:
 
> So it is a flawed model. If I were you I should enjoy your new position
> and find other places to exercise your tutorial skills.
 
> Chris
 
I disagree. While not perfect, it still gets more good answers than
usenet or any other website. The voting does help with moderation.
 
And who knows better whether a response answers a question than the
person who asked it?
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
"Öö Tiib" <ootiib@hot.ee>: Apr 08 12:01AM -0700

On Thursday, 7 April 2016 23:54:59 UTC+3, Vlad from Moscow wrote:
 
> http://stackoverflow.com/questions/36435991/3-recursion-problems-beginner-c/36436517
 
> was already down-voted one more time.:)
 
> What is the reason? Nothing more than the revenge.:)
 
Pointless paranoia. You have received the most likely reason
several times in this thread.
 
Lot of people consider giving direct answers to homework assignments
as very wrong thing to do. For most of them that is obvious and
expressing that openly. Downvote in SO is laughable penalty, you
may really get kicked out of university for cheating.
 
Some of those people are members of SO and when they read your
answer then they downvote it. Since it is obvious for them why they
downvoted they do not bother even to comment it.
Jerry Stuckle <jstucklex@attglobal.net>: Apr 08 07:50AM -0400

On 4/7/2016 4:54 PM, Vlad from Moscow wrote:
 
>> Bo Persson
 
> Moreover there is a dirty trick.
 
> Usually beginners do not know what answer to accept. In this case they take into account what answer is most upvoted.
 
Beginners know what answers help them. And did you ever think that just
maybe the reason the answer they accepted also had the most upvotes?
Maybe because it WAS the best answer?
 
Just giving them an answer solves THAT problem. But helping them learn
solves LOTS of problems.
 
I used to teach C++ (and other languages) for corporations. When
someone was stuck, I didn't give them answers. I asked them questions
which steered them in the right direction. It was much more effective.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Vlad from Moscow <vlad.moscow@mail.ru>: Apr 08 06:41AM -0700

On Friday, April 8, 2016 at 2:50:55 PM UTC+3, Jerry Stuckle wrote:
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================
 
You are totally wrong. Beginners in most cases can not say what answer is correct and the best. It is not rare when they accept answers that contain code bugs or wrong statements like that arrays are pointers in C/C++.
 
They can accept just an awful code that contains numerous magic numbers or inappropriate types and so on.
 
For example there is a question at SO where I answered that has two answers including mine. The other answer contains a function implementation with a bug. That is the code presented in the answer is invalid. But for a very simple test data it gives a valid result.:)
 
The author of the answer purposely down-voted my answer.
 
So the beginner accepted this answer with invalid code.:)
 
As I hope I may call myself a aprogrammer then I say that it is much better to see one time the valid code instead of several times listen its description.:)
 
For example it is not rare then I read a book and i do not understand what there is written about in the book until I at last will see the code.:) Having the code I can investigate it, modify it that to see what will happen after the modifications and so on.
 
To give an example of a good code is much more effective then to tell various stories about bad code.:)
 
And So is not designed to give questions to questions.
 
You and others like you forget that it is totally unimportant from the programming point of view what is the originator ofthe question. When you searches the internet for a solution of your problem or task only the problem description and a correct solution are important.
 
Qestion and answers are read by mnny users. They do not bother whether the auther of the qquestion is satisfied. For them it is interesting the problem described in the question and its solution and nothing more.
 
 
And only men without honour can down-vote a correct answer only because they do not like that somebody gave the answer. This starts a war when answers will be down-voted in revenge. This has nothing with programming. Such person should not be admited to programming forums. This has nothing common with programming and does not help enlarge your knowledge.
 
SO - a fascist website.
Jerry Stuckle <jstucklex@attglobal.net>: Apr 08 10:33AM -0400

On 4/8/2016 9:41 AM, Vlad from Moscow wrote:
>> which steered them in the right direction. It was much more effective.
 
>> --
 
 
> You are totally wrong. Beginners in most cases can not say what answer is correct and the best. It is not rare when they accept answers that contain code bugs or wrong statements like that arrays are pointers in C/C++.
 
Gee, that completely contradicts what I learned while teaching hundreds
of programmers. Only the beginner knows if the answer clarifies things
for him/her or not. No one else can.
 
> They can accept just an awful code that contains numerous magic numbers or inappropriate types and so on.
 
True. But if that's what it takes to help them understand, then it's good.
 
> For example there is a question at SO where I answered that has two answers including mine. The other answer contains a function implementation with a bug. That is the code presented in the answer is invalid. But for a very simple test data it gives a valid result.:)
 
OK, so it had a bug. If the OP understood that code and was able to fix
the bug, that answer was better for him/her.
 
> The author of the answer purposely down-voted my answer.
 
If your answer was like the one you posted early in this thread, then I
can understand why. I would have down-voted your answer, also.
 
> So the beginner accepted this answer with invalid code.:)
 
As I said - if it helped the beginner understand better than your code,
then that was the correct answer.
 
> As I hope I may call myself a aprogrammer then I say that it is much better to see one time the valid code instead of several times listen its description.:)
 
Giving someone the answer solves that problem - and that problem only.
Helping them understand the problem solves lots of problems.
 
> For example it is not rare then I read a book and i do not understand what there is written about in the book until I at last will see the code.:) Having the code I can investigate it, modify it that to see what will happen after the modifications and so on.
 
Just because that's the way YOU prefer doesn't mean it is the way OTHERS
prefer - or that it is even the best way.
 
> To give an example of a good code is much more effective then to tell various stories about bad code.:)
 
To help them understand the solution and come up with their own code is
much more effective than just giving them the code.
 
> And So is not designed to give questions to questions.
 
Not really true. You can find lots of questions where the responders
have their own questions.
 
> You and others like you forget that it is totally unimportant from the programming point of view what is the originator ofthe question. When you searches the internet for a solution of your problem or task only the problem description and a correct solution are important.
 
What you don't understand is there is a huge difference between guiding
a person to find their own answer and just giving them the answer. For
a beginner, the former is much more important.
 
> Qestion and answers are read by mnny users. They do not bother whether the auther of the qquestion is satisfied. For them it is interesting the problem described in the question and its solution and nothing more.
 
It doesn't matter how many people read the question. It's the OP who
needs to understand the answer.
 
 
> And only men without honour can down-vote a correct answer only because they do not like that somebody gave the answer. This starts a war when answers will be down-voted in revenge. This has nothing with programming. Such person should not be admited to programming forums. This has nothing common with programming and does not help enlarge your knowledge.
 
And only men with no clue will just give a beginner the code.
 
> SO - a fascist website.
 
I can see why you were banned. They care about their website and that
people get *GOOD* answers to their questions.
 
 
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Vlad from Moscow <vlad.moscow@mail.ru>: Apr 08 09:56AM -0700

On Friday, April 8, 2016 at 5:33:12 PM UTC+3, Jerry Stuckle wrote:
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================
 
You teach nobody at SO. It is not the purpose of the site. If you want to teach somebody you can go to a school or create your own site with your lectures.
 
At SO you ask and answer questions. And it is totally unimportant whether somebody who asked a question learned something.
 
The questions and answers are read by any programmer who can use already asked questions and answers to solve his own problem.
 
And he hopes that he will find a correct answer. When he sees that some correct answer is down-voted he will doubt whether the answer is indeed correct. So he just lost his time.
 
Programmesr are interesting in correct questions and answers from the programming point of view.
 
It is a main problem that such restricted persons as you try to dictate others what to do.
 
I am not going to ask your personal permission to answer a question. You have a right to write your own answer to a question as you like.
 
And when I see that somebody as you down-votes my answer in revenge I can conclude only that you are a man without honour. This opens a door to wars instead of discussing code from the programming point of view.
 
That is all.
 
SO - a fascist site of restricted persons.
scott@slp53.sl.home (Scott Lurndal): Apr 08 05:07PM


>That is all.
 
>SO - a fascist site of restricted persons.
 
None of this has anything to do with C++.
 
https://www.youtube.com/watch?v=1H-Y7MAASkg
Puppet_Sock <puppet_sock@hotmail.com>: Apr 08 06:59AM -0700

On Tuesday, March 22, 2016 at 10:44:57 PM UTC-4, woodb...@gmail.com wrote:
[snip]
> I like Ted Cruz. He would be an old school President --
> hard working and humble. We need another decent President.
 
Hard working and humble? Of course he is.
 
After all, he is Canadian. We are all hard working and humble.
 
After he runs for POTUS he can run for Canadian PM.
Ian Collins <ian-news@hotmail.com>: Apr 08 08:18PM +1200

On 04/08/16 08:22, Mr Flibble wrote:
>>> with crap.
 
>> Use a decent news server and you won't see its spam...
 
> Your news server doesn't show that guy's spam? What news server is that?
 
news.individual.net they have excellent spam filtering.
 
--
Ian Collins
red floyd <no.spam@its.invalid>: Apr 07 05:22PM -0700

On 4/7/2016 12:49 PM, Ramine wrote:
> Hello....
 
> And from now on i will not post about my USL programs here in this
> comp.arch group.
 
Except for the fact that this is comp.lang.c++, and not comp.arch,
you spamming idiot.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: