xwd: ./dsimple.c:277:17: warning: macro expands to multiple statements [-Wmultistatement-macros]

Walter Harms wharms at bfs.de
Sat Jan 26 10:42:43 UTC 2019


Perhaps it is better to remove the #define totaly.

just my 2 cents,
 re,
   wh

> "MEERSMAN Koen (EXT)" <koen.meersman.ext at eurocontrol.int> hat am 24. Januar
> 2019 um 11:00 geschrieben:
> 
> 
> Hi
> 
> When compiling dsimple.c with -Wall we get warning:
> 
>         ./dsimple.c: In function 'Select_Window_Args':
>         ./dsimple.c:277:17: warning: macro expands to multiple statements
> [-Wmultistatement-macros]
>          #define COPYOPT nargv++[0]=OPTION; nargc++
>                          ^~~~~
>         ./dsimple.c:283:27: note: in expansion of macro 'COPYOPT'
>                                    COPYOPT;
>                                    ^~~~~~~
>         ./dsimple.c:282:25: note: some parts of macro expansion are not
> guarded by this 'while'         clause
>                                  while (NXTOPTP)
>                                          ^~~~~
> 
> Question I have is what should the code do:
> 
> -- original code:
> 
>         #define COPYOPT nargv++[0]=OPTION; nargc++
> 
>             while (NXTOPTP) {
>                         if (!strcmp(OPTION, "-")) {
>                                 COPYOPT;
>                                 while (NXTOPTP)
>                                   COPYOPT;
>                                 break;
>                         }
> 
> -- fixed code
>         #define COPYOPT nargv++[0]=OPTION; nargc++
> 
>             while (NXTOPTP) {
>                         if (!strcmp(OPTION, "-")) {
>                                 COPYOPT;
> >                               while (NXTOPTP) {
> >                                 nargv++[0]=OPTION
> >                           }
>                                 break;
>                         }
> 
> -- now it does: (what looks wrong to me)
> 
>         #define COPYOPT nargv++[0]=OPTION; nargc++
> 
>             while (NXTOPTP) {
>                         if (!strcmp(OPTION, "-")) {
>                                 COPYOPT;
> >                               while (NXTOPTP) {
> >                                 COPYOPT;
> >                           }
> >                           nargc++
>                                 break;
>                         }
> 
> Can't find any usage of Select_Window_Args so I can't test.
> 
> 
> 
> Tnx,
> 
> Koen
> 
> 
> ----
> 
> 
> /*
>  * Select_Window_Args: a rountine to provide a common interface for
>  *                     applications that need to allow the user to select one
>  *                     window on the screen for special consideration.
>  *                     This routine implements the following command line
>  *                     arguments:
>  *
>  *                       -root            Selects the root window.
>  *                       -id <id>         Selects window with id <id>. <id>
> may
>  *                                        be either in decimal or hex.
>  *                       -name <name>     Selects the window with name <name>.
>  *
>  *                     Call as Select_Window_Args(&argc, argv) in main before
>  *                     parsing any of your program's command line arguments.
>  *                     Select_Window_Args will remove its arguments so that
>  *                     your program does not have to worry about them.
>  *                     The window returned is the window selected or 0 if
>  *                     none of the above arguments was present.  If 0 is
>  *                     returned, Select_Window should probably be called after
>  *                     all command line arguments, and other setup is done.
>  *                     For examples of usage, see xwininfo, xwd, or xprop.
>  */
> Window Select_Window_Args(
>                           int *rargc,
>                           char **argv)
> #define ARGC (*rargc)
> {
>         int nargc=1;
>         int argc;
>         char **nargv;
>         Window w=0;
> 
>         nargv = argv+1; argc = ARGC;
> #define OPTION argv[0]
> #define NXTOPTP ++argv, --argc>0
> #define NXTOPT if (++argv, --argc==0) usage()
> #define COPYOPT nargv++[0]=OPTION; nargc++
> 
>         while (NXTOPTP) {
>                 if (!strcmp(OPTION, "-")) {
>                         COPYOPT;
>                         while (NXTOPTP)
>                           COPYOPT;
>                         break;
>                 }
>                 if (!strcmp(OPTION, "-root")) {
>                         w=RootWindow(dpy, screen);
>                         continue;
>                 }
>                 if (!strcmp(OPTION, "-name")) {
>                         NXTOPT;
>                         w = Window_With_Name(dpy, RootWindow(dpy, screen),
>                                              OPTION);
>                         if (!w)
>                           Fatal_Error("No window with name %s
> exists!",OPTION);
>                         continue;
>                 }
>                 if (!strcmp(OPTION, "-id")) {
>                         NXTOPT;
>                         w=0;
>                         sscanf(OPTION, "0x%lx", &w);
>                         if (!w)
>                           sscanf(OPTION, "%lu", &w);
>                         if (!w)
>                           Fatal_Error("Invalid window id format: %s.",
> OPTION);
>                         continue;
>                 }
>                 COPYOPT;
>         }
>         ARGC = nargc;
> 
>         return(w);
> }
> 
> ____
> 
> This message and any files transmitted with it are legally privileged and
> intended for the sole use of the individual(s) or entity to whom they are
> addressed. If you are not the intended recipient, please notify the sender by
> reply and delete the message and any attachments from your system. Any
> unauthorised use or disclosure of the content of this message is strictly
> prohibited and may be unlawful.
> 
> Nothing in this e-mail message amounts to a contractual or legal commitment on
> the part of EUROCONTROL, unless it is confirmed by appropriately signed hard
> copy.
> 
> Any views expressed in this message are those of the sender.
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel


More information about the xorg-devel mailing list