Re: newbie libpq question... - Mailing list pgsql-interfaces

From Edmund Bacon
Subject Re: newbie libpq question...
Date
Msg-id 4190E641.7070601@onesystem.com
Whole thread Raw
In response to Re: newbie libpq question...  (Doug Homoelle <homoelle@ll.mit.edu>)
List pgsql-interfaces
Doug Homoelle wrote:
> That worked.  I guess I would have expected an error if there was a type
> mismatch, but like I said, my C is pretty rusty.
> 

If you are using gcc you can add -Wformat to your compile options to 
have it report if your printf() arguments don't match the format 
specifier - I don't know if other compilers do this, or how to turn it 
on if they do.

Note that for the compiler to know if your printf() arguments are 
correct, you have to supply the format string as a string literal to the 
call.  As an example, see the following program:


$ cat print.c

#include <stdio.h>

int main(void)
{    const char *format = "d = %f\n";    int d = 0;
    printf(format, d);
    d = 1;    printf("d = %f\n", d);
    return 0;
}

$ gcc -Wall -W print.c -o print
print.c: In function `main':
print.c:11: warning: double format, different type arg (arg 2)



-- 
Edmund Bacon <ebacon@onesystem.com>


pgsql-interfaces by date:

Previous
From: Doug Homoelle
Date:
Subject: Re: newbie libpq question...
Next
From: Peter Eisentraut
Date:
Subject: Re: ecpg: using cursor returned from a stored function