Skip site navigation (1) Skip section navigation (2)

Re: newbie libpq question...

From: Edmund Bacon <ebacon(at)onesystem(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Cc: Doug Homoelle <homoelle(at)ll(dot)mit(dot)edu>
Subject: Re: newbie libpq question...
Date: 2004-11-09 15:46:09
Message-ID: 4190E641.7070601@onesystem.com (view raw or flat)
Thread:
Lists: 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(at)onesystem(dot)com>

In response to

pgsql-interfaces by date

Next:From: Peter EisentrautDate: 2004-11-09 16:35:55
Subject: Re: ecpg: using cursor returned from a stored function
Previous:From: Doug HomoelleDate: 2004-11-09 14:54:49
Subject: Re: newbie libpq question...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group