On Wed, Apr 26, 2017 at 11:09 AM, Elardus Engelbrecht <
elardus.engelbre...@sita.co.za> wrote:

> David W Noon wrote:
>
> >You should not be passing a pointer (&x); everything is passed by value.
>
> Not many programmers are getting that right. Just that is making debugging
> extremely painfully difficult.
>
> I am just curious - Are there any compiler option(s) to help you to avoid
> that specific error?
>

​IIRC, the GNU C/C++ compiler is "smart" in that it can decode the format
string, if it's a literal, and compare it to the other parameters to make
sure they match. But, in general, this is not possible even with prototypes
when the function, such as printf() takes a "variable" parameter list. I.e.
the prototype for printf() is int printf( const char *, ...) . The the
three periods stand for "and more stuff" and so the compiler cannot
determine, in general, what that "other stuff" should be. It will diagnose
a prototyped mismatch such as:

[tsh009@it-johnmckown-linux junk]$ gcc -c bubba.c
bubba.c: In function ‘main’:
bubba.c:9:16: warning: passing argument 1 of ‘testfunc’ makes integer from
pointer without a cast [-Wint-conversion]
  rc = testfunc(&bubba, string);
                ^
bubba.c:5:5: note: expected ‘int’ but argument is of type ‘int *’
 int testfunc(int, char *);
     ^~~~~~~~
[tsh009@it-johnmckown-linux junk]$ cat bubba.c
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/time.h>
int testfunc(int, char *);
int main(int argc,char *argv[]) {
        int rc, bubba;
        char * string;
        rc = testfunc(&bubba, string);
        return(0);
}

​Please note that I used GCC under Linux bec​ause we don't have a license
for the IBM C/C++ compiler on z/OS.


>
> Groete / Greetings
> Elardus Engelbrecht
>
>
-- 
"Irrigation of the land with seawater desalinated by fusion power is
ancient. It's called 'rain'." -- Michael McClary, in alt.fusion

Maranatha! <><
John McKown

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to