请帮助类型惩罚警告 [英] help with type-punned warning please
问题描述
我有一个宏,我全面使用它来释放ram。我想
清理我的代码所以我不会收到这些警告。
#define sfree(x)_internal_sfree((void **)& x)
#define _internal_sfree(x)({if(x&& * x){free(* x); * x = NULL;}})
void somefunction(){
char * x = malloc(10);
int * y = malloc( 10);
sfree(x);
sfree(y);
}
结果为:
警告:取消引用类型惩罚指针将打破严格别名
规则
修复我缺乏线索的最佳方法是什么?
谢谢,
David
I have a macro that I use across the board for freeing ram. I''d like to
clean up my code so I don''t get these warnings.
#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } })
void somefunction() {
char *x = malloc(10);
int *y = malloc(10);
sfree(x);
sfree(y);
}
results in:
warning: dereferencing type-punned pointer will break strict-aliasing
rules
What''s the best way of fixing my lack of clue?
Thank you,
David
推荐答案
David Ford写道:
David Ford wrote:
我有一个宏,我全面使用它来释放ram。我想清理我的代码,所以我不会收到这些警告。
#define sfree(x)_internal_sfree((void **)& x)
#define _internal_sfree(x)({if(x&& * x){free(* x); * x = NULL;}})
void somefunction(){
char * x = malloc(10);
int * y = malloc(10);
sfree(x);
sfree(y) ;
结果:
警告:解除引用类型 - 惩罚指针将打破严格别名
什么是解决我缺乏线索的最佳方法?
I have a macro that I use across the board for freeing ram. I''d like to
clean up my code so I don''t get these warnings.
#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } })
void somefunction() {
char *x = malloc(10);
int *y = malloc(10);
sfree(x);
sfree(y);
}
results in:
warning: dereferencing type-punned pointer will break strict-aliasing
rules
What''s the best way of fixing my lack of clue?
这对你来说是最不妥当的问题。你的代码扩展为
void somefunction()
{
char * x = malloc(10);
int * y = malloc(10);
({
if((void **)& x& ;& *(void **)& x){
free(*(void **)& x); *(void **)& x = 0;}}) ;
({
if((void **)& y&& *(void **)& y){
free(*(void **)& y); *(void **)& y = 0;}});
}
表达式中有两个非法的支撑组实例。
That''s the least of your problems, it seems to me. Your code expands to
void somefunction()
{
char *x = malloc(10);
int *y = malloc(10);
( {
if ((void **) &x && *(void **) &x) {
free(*(void **) &x); *(void **) &x = 0;}}) ;
( {
if ((void **) &y && *(void **) &y) {
free(*(void **) &y); *(void **) &y = 0;}}) ;
}
which has two illegal instances of braced groups within expressions.
2004年2月26日星期四05:13:13 +0000,Martin Ambuhl写道:
On Thu, 26 Feb 2004 05:13:13 +0000, Martin Ambuhl wrote:
David Ford写道:
David Ford wrote:
我有一个宏,我全面使用它来释放ram。我想清理我的代码,所以我不会收到这些警告。
#define sfree(x)_internal_sfree((void **)& x)
#define _internal_sfree(x)({if(x&& * x){free(* x); * x = NULL;}})
void somefunction(){
char * x = malloc(10);
int * y = malloc(10);
sfree(x);
sfree(y) ;
结果:
警告:解除引用类型 - 惩罚指针将打破严格别名
什么是解决我缺乏线索的最佳方法?
I have a macro that I use across the board for freeing ram. I''d like to
clean up my code so I don''t get these warnings.
#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } })
void somefunction() {
char *x = malloc(10);
int *y = malloc(10);
sfree(x);
sfree(y);
}
results in:
warning: dereferencing type-punned pointer will break strict-aliasing
rules
What''s the best way of fixing my lack of clue?
在我看来,这是你问题中最少的问题。你的代码扩展为
void somefunction()
{*>
char * x = malloc(10);
int * y = malloc(10) ;
({
if((void **)& x&& *(void **)& x){
free(*(void *) *)& x); *(void **)& x = 0;}});
({
if((void **)& y&& *(void **)& y){
free(*(void **)& y); *(void **)& y = 0;}});
}
在表达式中有两个非法的支撑组实例。
That''s the least of your problems, it seems to me. Your code expands to
void somefunction()
{
char *x = malloc(10);
int *y = malloc(10);
( {
if ((void **) &x && *(void **) &x) {
free(*(void **) &x); *(void **) &x = 0;}}) ;
( {
if ((void **) &y && *(void **) &y) {
free(*(void **) &y); *(void **) &y = 0;}}) ;
}
which has two illegal instances of braced groups within expressions.
这是我得到的,请原谅,但这是怎么违法的?多年来我一直在使用
,它运行正常。它只是更新版本的gcc
我得到了这个警告。
({
if((void) **)& x& * *(void **)& x){
free(*(void **)& x);
*(void **)& x =((void *)0);
}
});
我是没有争论,我没有时间或机会跟上
约会。
Thanx,
大卫
This is what I get, and pardon, but how is this illegal? I''ve been using
this for years, it works fine. It''s just with the newer version of gcc
that I''m getting this warning.
({
if ( (void **)&x && *(void **)&x ) {
free(*(void **)&x);
*(void **)&x = ((void *)0);
}
});
I''m not arguing, I just haven''t had the time or opportunity to keep up to
date.
Thanx,
David
" David Ford" <哒********************** @ blue-labs.org>在留言中写道
news:pa **************************** @ blue-labs.org .. 。
"David Ford" <da**********************@blue-labs.org> wrote in message
news:pa****************************@blue-labs.org...
我有一个宏,我全面使用它来释放ram。我想清理我的代码,所以我不会收到这些警告。
#define sfree(x)_internal_sfree((void **)& x)
#define _internal_sfree(x)({if(x&& * x){free(* x); * x = NULL;}})
void somefunction(){
char * x = malloc(10);
int * y = malloc(10);
sfree(x);
sfree(y) ;
结果:
警告:解除引用类型 - 惩罚指针将打破严格别名
什么是解决我缺乏线索的最佳方法?
谢谢你,
大卫
I have a macro that I use across the board for freeing ram. I''d like to
clean up my code so I don''t get these warnings.
#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } })
void somefunction() {
char *x = malloc(10);
int *y = malloc(10);
sfree(x);
sfree(y);
}
results in:
warning: dereferencing type-punned pointer will break strict-aliasing
rules
What''s the best way of fixing my lack of clue?
Thank you,
David
这应该修复警告:
#include< stdio.h>
#include< stdlib.h>
#define sfree(x)_internal_sfree((void **)& x)
#define _internal_sfree(x)do {\
if((x)& & *(x))\
{\
免费(*(x)); \
*(x)= NULL; \
} \
}而(0)
无效功能()
{
char * x = malloc(10);
int * y = malloc(10);
sfree(x );
sfree(y);
}
-
Vijay Kumar R Zanvar
我的主页 - http://www.geocities.com / vijoeyz /
这篇关于请帮助类型惩罚警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!