Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15813 > unrolled thread

macro

Started bydspfun <dspfun@hotmail.com>
First post2012-01-15 05:29 -0800
Last post2012-01-16 12:01 +0000
Articles 4 on this page of 44 — 19 participants

Back to article view | Back to comp.lang.c


Contents

  macro dspfun <dspfun@hotmail.com> - 2012-01-15 05:29 -0800
    Re: macro Dr Nick <3-nospam@temporary-address.org.uk> - 2012-01-15 13:44 +0000
      Re: macro dspfun <dspfun@hotmail.com> - 2012-01-15 05:58 -0800
        Re: macro "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-01-15 15:34 +0100
        Re: macro "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-01-15 06:37 -0800
          Re: macro dspfun <dspfun@hotmail.com> - 2012-01-15 07:28 -0800
            Re: macro Philip Lantz <prl@canterey.us> - 2012-01-15 17:30 -0800
              Re: macro Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-16 00:18 -0800
                Re: macro Hans Vlems <hvlems@freenet.de> - 2012-01-16 00:52 -0800
                  Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-16 22:08 +1300
                  Re: macro Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-16 03:04 -0800
                  Re: macro Markus Wichmann <nullplan@gmx.net> - 2012-01-16 12:42 +0100
          Re: macro jgk@panix.com (Joe keane) - 2012-01-16 14:48 +0000
            Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-16 12:01 -0800
              Re: macro Philip Lantz <prl@canterey.us> - 2012-01-17 01:02 -0800
                Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-17 13:05 -0800
                  Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-18 13:12 +1300
                    Re: macro dspfun <dspfun@hotmail.com> - 2012-01-18 01:05 -0800
                      Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-18 22:57 +1300
                        Re: macro "osmium" <r124c4u102@comcast.net> - 2012-01-18 06:22 -0600
                        Re: macro dspfun <dspfun@hotmail.com> - 2012-01-18 07:50 -0800
                          Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 14:09 +1300
                        Re: macro blp@cs.stanford.edu (Ben Pfaff) - 2012-01-18 11:28 -0800
                        Re: macro Kaz Kylheku <kaz@kylheku.com> - 2012-01-18 21:09 +0000
                          Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 15:08 +1300
                            [OT] Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 15:58 +1300
                              Re: [OT] Re: macro Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-20 12:22 +0000
                                Re: [OT] Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-21 07:58 +1300
                            Re: macro James Kuyper <jameskuyper@verizon.net> - 2012-01-19 22:47 -0500
                              Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 17:06 +1300
                                Re: macro James Kuyper <jameskuyper@verizon.net> - 2012-01-20 00:12 -0500
                                  Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 18:28 +1300
                            Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-20 03:21 -0800
                          Re: macro Shao Miller <sha0.miller@gmail.com> - 2012-01-20 10:50 -0500
                            Re: macro Shao Miller <sha0.miller@gmail.com> - 2012-01-20 11:46 -0500
                        Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-18 14:24 -0800
                        Re: macro jgk@panix.com (Joe keane) - 2012-01-18 22:36 +0000
                          Re: macro Kaz Kylheku <kaz@kylheku.com> - 2012-01-18 22:50 +0000
              Re: macro jgk@panix.com (Joe keane) - 2012-01-17 22:08 +0000
    Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-15 08:00 -0800
    Re: macro NEON China BLUE <chine.bleu@yahoo.com> - 2012-01-15 08:15 -0800
    Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-16 09:04 +1300
      Re: macro Philip Lantz <prl@canterey.us> - 2012-01-15 17:36 -0800
    Re: macro Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-16 12:01 +0000

Page 3 of 3 — ← Prev page 1 2 [3]


#15821

FromNEON China BLUE <chine.bleu@yahoo.com>
Date2012-01-15 08:15 -0800
Message-ID<chine.bleu-BA96A9.08151615012012@news.eternal-september.org>
In reply to#15813
In article <89018f82-9f45-4e72-a0a2-8424e91752b6@g41g2000yqa.googlegroups.com>,
 dspfun <dspfun@hotmail.com> wrote:

> Hi all!
> 
> Can you see anything wrong or "bad" with the following macro?
> 
> #define LOG(level, msg) \
> openlog (__FUNCTION__, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
> \
> syslog (level, "%s", msg);\
> closelog ();
> 
> I have problems using the macro with ternary operators. I believe it
> should have parantheses around it all, but I cannot get it right.

expr, expr is still an expression while expr; expr; is two statements even 
though they are semantickally equivalent. You can do

#define LOG(level, msg) ( \
    openlog (__FUNCTION__, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER), \
    syslog (level, "%s", msg), \
    closelog () \
)

and then use LOG wherever you could do a function call.

-- 
My name Indigo Montoya.      |                  Yippee-kay-yay, eh.
You flamed my father.        |       I'm whoever you want me to be.
Prepare to be spanked.       |  Annoying Usenet one post at a time.
Stop posting that!           |    At least I can stay in character.

[toc] | [prev] | [next] | [standalone]


#15831

FromIan Collins <ian-news@hotmail.com>
Date2012-01-16 09:04 +1300
Message-ID<9ngpplFob3U1@mid.individual.net>
In reply to#15813
On 01/16/12 02:29 AM, dspfun wrote:
> Hi all!
>
> Can you see anything wrong or "bad" with the following macro?
>
> #define LOG(level, msg) \
> openlog (__FUNCTION__, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
> \
> syslog (level, "%s", msg);\
> closelog ();
>
> I have problems using the macro with ternary operators. I believe it
> should have parantheses around it all, but I cannot get it right.

Reduce the macro to a simple function call:

void log( const char* func, int level, const char* msg )
{
   openlog( func, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER );
   syslog( level, "%s", msg );
   closelog();
}

#define LOG(level, msg) log( __func__, level, msg )

Why do people insist on making extra work for them selves by trying to 
write overly complex macros were a function will do the job?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#15838

FromPhilip Lantz <prl@canterey.us>
Date2012-01-15 17:36 -0800
Message-ID<MPG.297d1ee3790b28b3989685@news.eternal-september.org>
In reply to#15831
Ian Collins wrote:
> 
> On 01/16/12 02:29 AM, dspfun wrote:
> > Hi all!
> >
> > Can you see anything wrong or "bad" with the following macro?
> >
> > #define LOG(level, msg) \
> > openlog (__FUNCTION__, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
> > \
> > syslog (level, "%s", msg);\
> > closelog ();
> >
> > I have problems using the macro with ternary operators. I believe it
> > should have parantheses around it all, but I cannot get it right.
> 
> Reduce the macro to a simple function call:
> 
> void log( const char* func, int level, const char* msg )
> {
>    openlog( func, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER );
>    syslog( level, "%s", msg );
>    closelog();
> }
> 
> #define LOG(level, msg) log( __func__, level, msg )
> 
> Why do people insist on making extra work for them selves by trying to 
> write overly complex macros were a function will do the job?

Oh, good point! I shoulda read the whole thread before I sent my 
response.

Philip

[toc] | [prev] | [next] | [standalone]


#15844

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-01-16 12:01 +0000
Message-ID<slrnjh84bt.1ls.grahn+nntp@frailea.sa.invalid>
In reply to#15813
On Sun, 2012-01-15, dspfun wrote:
> Hi all!
>
> Can you see anything wrong or "bad" with the following macro?
>
> #define LOG(level, msg) \
> openlog (__FUNCTION__, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
> \
> syslog (level, "%s", msg);\
> closelog ();

(These comments are strictly off-topic since syslog() is a Unix thing:)

Apart from what Ian Collins wrote, there are some related to
openlog()/syslog() themselves. One that I see is that you're not
supposed to log with the function name as the "logger identity" but
rather a process or a program name.

Also, sooner or later you will want printf-style arguments.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.c


csiph-web