Great! Will it warn about more %n$ than are supported? I hope? Not that we're 
likely to make that mistake again...

...phsiii (limping still from self-inflicted foot wound)

-----Original Message-----
From: IBM Mainframe Discussion List <[email protected]> On Behalf Of 
Linda Chui
Sent: Monday, October 20, 2025 2:14 PM
To: [email protected]
Subject: Re: Anyone using XL C?

On Sun, 5 Oct 2025 22:58:43 +0200, Bernd Oppolzer <[email protected]> 
wrote:

>Now that I know that this feature is not standard C, I'm sort of 
>relieved that I didn't know about it and "fixed" the problem in my 
>recent answer by simply removing the 1$ etc. flags, which didn't tell 
>me anything :-)
>
>Another remark from the view point of a compiler builder: these nn$ 
>flags, which allow the addressing of the subsequent parameters of 
>printf etc. out of sequence (say, by index), require that all the 
>parameters or addresses of printf are placed in a vector of appropriate 
>size, so that they can be referenced later. The size of this vector is 
>the NL_ARGMAX constant mentioned earlier. This vector etc. is not 
>necessary, if the parameters are processed in the same sequence as the 
>% tags appear in the printf pattern, which is also faster IMO.
>So I'm not surprised that this feature is not part of the C (library) 
>standard.
>
>BTW: I really hope that clever C compilers do some optimization on 
>printf and similar function calls, given constant patterns - and maybe 
>extended diagnostics, such as: do the parameters agree with the tags in 
>the pattern? Does the count of parameters match the number of tags in 
>the pattern?
>If the patterns are variables, then, of course, there is no chance ...
>
>Kind regards
>
>Bernd
>


Yes, the newer Open XL C/C++ compiler does check for things like this. Helps 
avoid nasty bugs and issues in your code so a great thing to take advantage of. 
For example, the following program will let you know about type mismatch, too 
many arguments, and too few arguments!

- a.c –
#include <stdio.h>

int main(void) {
  printf("Hello World! Year: %s, %s\n", __DATE__, __LINE__, __STDC_VERSION__);
  printf("Hello World! Year: %s, %s\n", __DATE__, "hehe", __LINE__, 
__STDC_VERSION__);
  printf("Hello World! Year: %s, %s\n", __DATE__);
  return 55;
}
- end a.c -

> ibm-clang a.c                                                                 
>                                                
a.c:4:51: warning: format specifies type 'char *' but the argument has type 
'int' [-Wformat]
    4 |   printf("Hello World! Year: %s, %s\n", __DATE__, __LINE__, 
__STDC_VERSION__);
      |                                  ~~               ^~~~~~~~
      |                                  %d
<scratch space>:6:1: note: expanded from here
    6 | 4
      | ^
a.c:5:59: warning: data argument not used by format string [-Wformat-extra-args]
    5 |   printf("Hello World! Year: %s, %s\n", __DATE__, "hehe", __LINE__, 
__STDC_VERSION__);
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                    ^
<scratch space>:7:1: note: expanded from here
    7 | 5
      | ^
a.c:6:35: warning: more '%' conversions than data arguments 
[-Wformat-insufficient-args]
    6 |   printf("Hello World! Year: %s, %s\n", __DATE__);
      |                                  ~^
3 warnings generated.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
[email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to