On 03/22/2014 04:00 PM, Tom Lane wrote:
On the other side, coding with the explicit cast helps guard against far
more dangerous coding errors, which the compiler will*not* help you with.
What if myextra is actually of type "int64 *"?
Indeed, neither "gcc -Wall -Wextra -std=c89 -pedantic" nor "clang
-Weverything -Wno-shadow -std=c89 -pedantic" issues a warning in such
case. "clang --analyze", however, does. Perhaps TenDRA would, if it ever
worked.
This message is meant to be merely informative, since I've put some
effort into this test. I'm not trying to argue.
#include <stdlib.h>
typedef long int int64;
int main(void)
{
int *myextra;
/* with explicit casting */
myextra = (int *) malloc(sizeof (int));
free(myextra);
/* with no explicit casting */
myextra = malloc(sizeof (int));
free(myextra);
/* myextra now becomes int64 */
{
int64 *myextra;
/* with explicit casting */
myextra = (int *) malloc(sizeof (int)); /* [1], [2]. and [3] warn here */
free(myextra);
/* with no explicit casting */
myextra = malloc(sizeof (int)); /* Only [3] warns here */
free(myextra);
}
return 0;
}
/*
1: gcc 4.8.2: gcc -Wall -Wextra -std=c89 -pedantic /tmp/test.c
2: clang 3.5.0: clang -Weverything -Wno-shadow -std=c89 -pedantic /tmp/test.c
3: clang 3.5.0: clang --analyze /tmp/test.c
*/
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers