是这个法律声明/不正确的输出 [英] is this legal declaration/not correct output
问题描述
嗨!
我已经写了一些代码安静,但是我想知道它是否合法用于ansi-c
我编译它没有问题,但由于我缺乏经验并且
输出不正确,我有疑问。谢谢你的帮助!
#include< stdio.h>
#include< stdlib.h>
#define __buff(s,c)s_c
int main(){
int i;
for(i = 0; i< 10; i ++){
int __buff(* send,i);
}
for(i = 0; i< 10; i ++){
__buff(send,i)= i;
}
for(i = 0; i< 10; i ++){
printf("%d \ n",__ buff(send,i));
}
返回0;
}
输出总是3 ...
我的意图是用循环来处理几个int指针,因为我是
懒得写所有int'的...
我想制作X int指针的数量
int * pointer_1
.....
int * pointer_X
>
为所有分配内存
pointer_1 = malloc(sizeof(* pointer_1))
.....
pointer_X = malloc(sizeof(* pointer_X))
用值填充它们
并做点什么
如果这种方式不正确就会出现黑客攻击像我这样懒惰的程序员?
再次感谢你!
LR
Hi!
I have written some peace of code, but I wonder if it''s legal for ansi-c
I have no problem to compiling it, but since I''m inexperience and the
output is not correct I have doubts. Thank you for help!
#include <stdio.h>
#include <stdlib.h>
#define __buff(s, c) s_c
int main(){
int i;
for(i=0;i<10;i++){
int __buff(*send,i);
}
for(i=0;i<10;i++){
__buff(send,i) = i;
}
for(i=0;i<10;i++){
printf("%d \n",__buff(send,i));
}
return 0;
}
The output is always 3...
My intentions is to deal with several int pointer with loops, since I''m
lazy to write all int''s...
I want to make X number of int pointer
int *pointer_1
.....
int *pointer_X
allocate memory for all
pointer_1=malloc(sizeof( *pointer_1))
.....
pointer_X=malloc(sizeof( *pointer_X))
fill them with values
and do something
if this way not proper is there a "hack" for lazy programmer like me?
Thank you again!
L R
推荐答案
抱歉......旧代码.. :)这里是正确的版本
#include< stdio.h>
#include< stdlib.h>
#define __buff(s,c)s_c
int main(){
int i;
int __buff(* send,ZERO);
for(i = 0; i< 4; i ++) {
int __buff(* send,i);
}
for(i = 0; i< 4; i ++){
__buff(send,i)= malloc(sizeof(__buff(* send,i)));
}
for( i = 0; i< 4; i ++){
__buff(send,i)= i;
}
for(i = 0 ; i< 4; i ++){
printf("%d \ n",__ buff(send,i));
}
返回0;
}
sorry... old code.. :) here is the "right version"
#include <stdio.h>
#include <stdlib.h>
#define __buff(s, c) s_c
int main(){
int i;
int __buff(*send, ZERO);
for(i=0;i<4;i++){
int __buff(*send,i);
}
for(i=0;i<4;i++){
__buff(send,i) = malloc(sizeof (__buff(*send,i)));
}
for(i=0;i<4;i++){
__buff(send,i) = i;
}
for(i=0;i<4;i++){
printf("%d \n",__buff(send,i));
}
return 0;
}
文章< 46 ******** ***************@news.luth.se>,
Carramba< us ** @ example.netwrote:
In article <46***********************@news.luth.se>,
Carramba <us**@example.netwrote:
> #include< stdio.h>
#include< stdlib.h>
#define __buff(s,c)s_c
>#include <stdio.h>
#include <stdlib.h>
#define __buff(s, c) s_c
它定义了一个类似于对象的宏__buff(),它带有两个参数,
但无论参数是什么,总是发出变量名字
s_c。字面上,ess强调cee,完全与给予宏的s $ / b $ b和c参数无关。你可以从中推断出你b / b观察到的输出行为。
你不能以你想的方式一起加入参数;
it -is-可以从宏参数创建新的标识符,但
它需要更高级的预处理器工作,并且替换是
总是在-compile-时完成,不是在执行时。
我建议您要做的是使用数组,而不是
尝试动态生成新的变量名。
That defines an object-like macro __buff() that takes two parameters,
but no matter what the parameters are, always emits the variable name
s_c . Literally, ess underscore cee, totally unrelated to the s
and c parameters given to the macro. The output behaviour you
observe can be deduced from this.
You cannot just join parameters together in the manner you were thinking;
it -is- possible to create new identifiers from macro parameters, but
it requires fancier preprocessor work, and the replacement is
always done at -compile- time, not at execution time.
I would suggest that what you want to do is use arrays, not
try to generate new variable names dynamically.
> int main(){
int i;
int __buff(* send,ZERO);
for( i = 0; i< 4; i ++){
int __buff(* send,i);
}
for(i = 0; i< 4; i ++){
__buff(send,i)= malloc(sizeof(__buff(* send,i)));
for(i = 0; i< 4; i ++){
__buff(send,i)= i;
}
for(i = 0; i< 4; i ++){
printf("%d \ n",__ buff) ,i));
}
返回0;
}
>int main(){
int i;
int __buff(*send, ZERO);
for(i=0;i<4;i++){
int __buff(*send,i);
}
for(i=0;i<4;i++){
__buff(send,i) = malloc(sizeof (__buff(*send,i)));
}
for(i=0;i<4;i++){
__buff(send,i) = i;
}
for(i=0;i<4;i++){
printf("%d \n",__buff(send,i));
}
return 0;
}
-
没有人有权通过
要求经验证据来摧毁他人的信念。 - Ann Landers
--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers
Walter Roberson skrev:
Walter Roberson skrev:
文章< 46 ****** *****************@news.luth.se>,
Carramba< us ** @ example.netwrote:
In article <46***********************@news.luth.se>,
Carramba <us**@example.netwrote:
> #include< stdio.h>
#include< stdlib.h>
#define __buff(s,c)s_c
>#include <stdio.h>
#include <stdlib.h>
#define __buff(s, c) s_c
它定义了一个类似于对象的宏__buff(),它带有两个参数,
但无论参数是什么,总是发出变量名字
s_c。字面上,ess强调cee,完全与给予宏的s $ / b $ b和c参数无关。你可以从中推断出你观察到的输出行为。
你不能以你想的方式将参数加在一起;
That defines an object-like macro __buff() that takes two parameters,
but no matter what the parameters are, always emits the variable name
s_c . Literally, ess underscore cee, totally unrelated to the s
and c parameters given to the macro. The output behaviour you
observe can be deduced from this.
You cannot just join parameters together in the manner you were thinking;
我害怕所以
I was afraid so
它是 - 可能从宏参数创建新标识符,但是
它需要更高级的预处理器工作,并且替换是
总是在-compile- time完成,而不是在执行时。
it -is- possible to create new identifiers from macro parameters, but
it requires fancier preprocessor work, and the replacement is
always done at -compile- time, not at execution time.
你能亲切并建议怎么做吗?
我真的很想学习一些奇特的东西:)是没关系他们
是在编译时创建的。
could you by kind and suggest how to do it?
I would really like to learn some fancy c stuff :) is it ok that they
are created at compile time.
我建议你想要做的是使用数组,而不是
尝试动态生成新变量名。
I would suggest that what you want to do is use arrays, not
try to generate new variable names dynamically.
这篇关于是这个法律声明/不正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!