pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edmund Bacon <ebacon@onesystem.com>
To: pgsql-interfaces@postgresql.org
Cc: Doug Homoelle <homoelle@ll.mit.edu>
Subject: Re: newbie libpq question...
Date: Tue, 09 Nov 2004 08:46:09 -0700
Message-ID: <4190E641.7070601@onesystem.com> (raw)
In-Reply-To: <1100012089.2819.13.camel@             >
References: <1099953369.2819.11.camel@>
	<20041108182155.086d9d58.darcy@druid.net>
	<1100012089.2819.13.camel@ >

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>



view thread (8+ messages)  latest in thread

Message-ID: <4190E641.7070601@onesystem.com>
Permalink:  ../4190E641.7070601@onesystem.com/
Also on:    postgresql.org/message-id/4190E641.7070601@onesystem.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: ebacon@onesystem.com, homoelle@ll.mit.edu
  Subject: Re: newbie libpq question...
  In-Reply-To: <4190E641.7070601@onesystem.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox