× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Frank,
I think that your reference to K&R is a joke.
K&R book is a book for learning language. It is not for learning style.
They used "forever" as an example what CAN BE done using #define but they never said that it SHOULD BE done.
Feel the difference.

I personally hate this sort of macros because they make program unreadable for others - exactly what Barbara told you earlier.
So: think of the people who will read your code, use clear constructions!

Next thing - do not overestimate the meaning of programming style.
I am reading the thread and sometimes do not agree.

Mark advises to format this way:
if (f EQ NULL) {
printf("can't open file %s\n", PFILENAME);
exit(rc);
}

I personally prefer to write it another way:
if (f == NULL)
{
printf("can't open file %s\n", PFILENAME) ;
exit(rc) ;
}

But there was one sentence in Mark's mail that impressed me really much an with which I agree 100%.
This is the last sentence about the style:

"Whatever you decide to do, strive for consistency."

Now on ability to interprete code with macros. Don't be so sure.
There are even contests on who will write the most difficult for understanding C code - google it and try to understand.

I once had a collegue who was a big fan of macros.
Here's a part of his real code:
-----------------------------------------------------------------------
#define readacc(a) ( rfb =_Rreadk( sc20lf, &buf, sizeof( buf ), ( a )\
, gfcus, 6 ))
#define bytes ( rfb->num_bytes )
#define buflen ( sizeof( buf ))
int both = 0 ;

readacc ( __KEY_EQ );
for ( ; ( bytes == buflen ) && both < 2 ; readacc ( __KEY_NEXTEQ ))
-----------------------------------------------------------------------
It was a little too much for me....

Jevgeni.


-----Original Message-----
From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Frank Kolmann
Sent: Friday, April 04, 2014 11:24 AM
To: c400-l
Subject: [C400-L] C macros

Hi Barbara



Thank you for your comments. I am happy to start a discussion on macros.

Please understand I value and appreciate your comments.

Couple of points.



I found the 'forever' macro in this book. pp97



The C programming Language

By Brian W. Kernighan and Dennis M. Ritchie.

Published by Prentice-Hall in 1988

ISBN 0-13-110362-8 (paperback)

ISBN 0-13-110370-9

-- exerpt --

Any name may be defined with any replacement text. For example

#define forever for (;;) /* infinite loop */

defines a new word, forever, for an infinite loop.



Do you mean to say that the C gods K&R themselves published weird code?



Also if C programmers cannot cope with macros does not that imply they

are not truly C programmers.



Why does C have the ability to have such marco substitution if it is

not to be used.

Particularly if it helps avoid a potential bug that the compiler

does not report and only manifests at execution time (= for ==).



I believe I will have no problem interpreting the standard C

code or other C code with macros.



Frank





*Subject: Re: First C Program

*From: Barbara Morris <bmorris@xxxxxxxxxx>

*Date: Thu, 03 Apr 2014 13:42:13 -0400



Hi Frank, I have been thinking about the use of macros such as

EQ, forever, NE etc, and I think you are doing yourself a disservice

by using these macros as a beginner C programmer. Here are some of the
reasons:



You will find it less easy to read "normal" C code if you don't get

used to seeing *and quickly interpreting* things like != == for(;;)



You will find it more difficult to incorporate code that you find on
the
web.

You will have to either change all the == and != to use your macros,

or perhaps even worse, you will have a mixture of EQ and ==.



You will not be able to post snippets of code to forums without

replacing your macros. I wouldn't post weird code like that to any
forum

even with an explanation for what the macros mean.

The discussion would almost certainly be more about the use of the
macros than about whatever question you were trying to ask.
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/c400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.