基内斯 [英] Quines

查看:50
本文介绍了基内斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。任何人都可以解释为什么以下

代码的输出是Hello?没有包含头文件,代码工作(编译

作为'c''代码,在Visual C ++ 2008(快递)上具有最严格的警告级别!


我得到两个警告:

1.warning C4431:缺少类型说明符 - 假设int。注意:C不再

支持default-int

2.warning C4013:''printf''未定义;假设extern返回int


main()

{

char * c =" Hello";

printf(c,34,c,34);

}

代码打印Hello无论

printf语句中使用的整数值(+ ve和-ve)

__________________________________________________ ____________________


其次。


#include< stdio.h>

main(){


char * c =" \\\" #include< stdio.h>%cmain(){char * c =%c%c%c%.102s%cn%c

; printf (C + 2,C [102],C [1],* C *,C,C,* C,C [1]);出口(0) ;} \ n" ;;


printf(c + 2,c [102],c [1],* c,* c,c,* c,c [1] ); / *这条线怎么样?* /

退出(0);

}


任何人都可以解释在printf声明?


谢谢

Hello.Can anyone please explain why the output of the following
code is Hello? No header file is included and the code works (Compiled
as a ''c'' code with the strictest warning level on Visual C++ 2008(express) !

I get the two warnings :
1.warning C4431: missing type specifier - int assumed. Note: C no longer
supports default-int
2.warning C4013: ''printf'' undefined; assuming extern returning int

main()
{
char *c="Hello";
printf(c,34,c,34);
}
The code prints Hello irrespective of the integer values used in the
printf statement(both +ve and -ve)

__________________________________________________ ____________________

Secondly.

#include<stdio.h>
main() {

char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c% c%.102s%cn%c
;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}\n";

printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]); /*What about this line?*/
exit(0);
}

Can anyone explain what happens in the printf statement?

Thank You

推荐答案

1月7日12:07 * pm,Tarique< ; peo _... @ yahoo.comwrote:
On Jan 7, 12:07*pm, Tarique <peo_...@yahoo.comwrote:

Hello.Can任何人都可以解释为什么以下

代码的输出是Hello?没有包含头文件,代码工作(编译

作为'c''代码,在Visual C ++ 2008(快递)上具有最严格的警告级别!


我得到两个警告:

1.warning C4431:缺少类型说明符 - 假设int。注意:C不再

支持default-int

2.warning C4013:''printf''undefined;假设extern返回int
Hello.Can anyone please explain why the output of the following
code is Hello? No header file is included and the code works (Compiled
as a ''c'' code with the strictest warning level on Visual C++ 2008(express)!

I get the two warnings :
1.warning C4431: missing type specifier - int assumed. Note: C no longer
supports default-int
2.warning C4013: ''printf'' undefined; assuming extern returning int



这是未定义的行为。你正在调用一个varadic函数
没有原型的

This is undefined behavior. You are calling a varadic function
without the presence of a prototype.


main()

{

* * * * char * c =" Hello";

* * * * printf(c,34,c,34);}


代码打印Hello无论

printf语句中使用的整数值(+ ve和-ve)
main()
{
* * * * char *c="Hello";
* * * * printf(c,34,c,34);}

The code prints Hello irrespective of the integer values used in the
printf statement(both +ve and -ve)



格式中没有转换说明符字符串。

There are no conversion specifiers in the format string.


_____________________________________ _____________ ____________________


其次。


#include< stdio.h>

main(){


char * c =" \\\" #include< stdio.h>%cmain(){char * c =%c%c%c%.102s%cn %c

; printf(c + 2,c [102],c [1],* c,* c,c,* c,c [1]);退出(0);} \\\
" ;;


printf(c + 2,c [102],c [1],* c,* c,c,* c,c [1]); / *这条线怎么样?* /

退出(0);
__________________________________________________ ____________________

Secondly.

#include<stdio.h>
main() {

char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c% c%.102s%cn%c
;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}\n";

printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]); /*What about this line?*/
exit(0);



您的格式字符串从c的第3个字符开始。请注意main()之前的%c

?这是第一个格式说明符。剩下的应该是显而易见的。

Your format string starts at the 3rd character of c. Notice the %c
before main()? That is the first format specifier. The rest should
be obvious.


}


任何人都可以解释在printf声明?


谢谢
}

Can anyone explain what happens in the printf statement?

Thank You


Tarique写道:
Tarique wrote:

Hello.Can任何人都可以解释为什么以下

代码的输出是Hello?没有包含头文件,代码可以工作(编译

作为'c''代码,在Visual C ++ 2008(快递)上具有最严格的警告级别!
Hello.Can anyone please explain why the output of the following
code is Hello? No header file is included and the code works (Compiled
as a ''c'' code with the strictest warning level on Visual C++ 2008(express) !



它有效,因为有时候你发生了一个不幸的事故,这使得有缺陷的代码看起来工作正常。你不应该太担心

关于详细原因;只需更正你的代码。

It works because sometimes you have an unlucky accident which makes
defective code appear to work correctly. You shouldn''t worry too much
about the details of why; just correct your code.


我得到两个警告:

1.warning C4431:缺少类型说明符 - 假设为int注意:C不再

支持default-int
I get the two warnings :
1.warning C4431: missing type specifier - int assumed. Note: C no longer
supports default-int



更容易

es it easier


2.warning C4013:''printf''未定义;假设extern返回int
2.warning C4013: ''printf'' undefined; assuming extern returning int



printf()的正确返回类型恰好是''int' ',所以

假设意外工作。另一方面,它应该有

假设printf()是一个普通的函数,没有ta variadic one,

原则上可能导致问题。

The correct return type of printf() happens to be ''int'', so that
assumption accidentally worked. On the other hand, it should have
assumed that printf() is an ordinary function, not a variadic one,
which could in principle cause problems.


main()

{

char * c =" Hello";

printf(c,34,c,34);

}
main()
{
char *c="Hello";
printf(c,34,c,34);
}



由于您的程序打印了Hello,因此该编译器的变量函数的传递约定似乎可能是

兼容那些用于普通函数的函数,至少在你从未使用
访问变量参数时,就像在这种情况下一样。

Since your program printed "Hello", it seems likely that the argument
passing conventions for variadic functions for this compiler are
compatible with those for ordinary functions, at least when you never
access the variable arguments, as in this case.


代码打印Hello而不管

printf语句中使用的整数值(+ ve和-ve)
The code prints Hello irrespective of the integer values used in the
printf statement(both +ve and -ve)



因为解释了第一个''c''作为不包含

格式说明符的格式字符串,printf()没有理由读取任何其他

参数。

Since the first ''c'' was interpreted as format string that contained no
format specifiers, printf() had no reason to read any of it''s other
arguments.


______________________ ____________________________ ____________________


其次。


#include< stdio.h>

main(){


char * c =" \\\" #include< stdio.h>%cmain(){char * c =%c%c%c%.102s%cn %c; printf(c + 2,c [102],c [1],* c,* c,c,* c,c [1])退出(0);} \ n;;


printf(c + 2,c [102],c [1],* c,* c,c,* c,c [1]); / *这条线怎么样?* /

退出(0);

}


任何人都可以解释在printf声明?
__________________________________________________ ____________________

Secondly.

#include<stdio.h>
main() {

char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c% c%.102s%cn%c;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]) exit(0);} \n";

printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]); /*What about this line?*/
exit(0);
}

Can anyone explain what happens in the printf statement?



你从哪里得到那些代码?是来自混淆的C竞赛吗?

简单规则:永远不要写那样的代码。但是,如果你坚持要求b / b
试图搞清楚,我建议再花一点时间来讨论它,然后再寻求帮助。这很糟糕,因为它很复杂,而且难以阅读,但它使用的C的功能都相对简单 - 你应该能够解决它没有

寻求帮助。

Where did you get that code? Is it from an obfuscated C contest?
Simple rule: never write code like that. However, if you insist on
trying to figure it out, I recommend taking a little bit longer to
look at it before asking for help; it''s awful because it''s complicated
and hard to read, but the features of C that it uses are all
relatively straightforward - you should be able to solve it without
asking for help.


1月7日,12:41 * pm,jameskuy ... @ verizon.net写道:
On Jan 7, 12:41*pm, jameskuy...@verizon.net wrote:

Tarique写道:
Tarique wrote:

Hello.Can任何人都可以解释为什么输出如下

代码是你好吗?没有包含头文件,代码工作(编译

作为'c''代码,在Visual C ++ 2008(快递)上具有最严格的警告级别!
Hello.Can anyone please explain why the output of the following
code is Hello? No header file is included and the code works (Compiled
as a ''c'' code with the strictest warning level on Visual C++ 2008(express) !



它的工作原理是因为有时你发生了一个不幸的事故,这使得有缺陷的代码看起来工作正常。你不应该太担心

关于详细原因;只需更正你的代码。


It works because sometimes you have an unlucky accident which makes
defective code appear to work correctly. You shouldn''t worry too much
about the details of why; just correct your code.


我得到两个警告:

1.warning C4431:缺少类型说明符 - 假设为int注意:C不再

支持default-int
I get the two warnings :
1.warning C4431: missing type specifier - int assumed. Note: C no longer
supports default-int



更容易

es it easier


2.warning C4013:''printf''未定义;假设extern返回int
2.warning C4013: ''printf'' undefined; assuming extern returning int



printf()的正确返回类型恰好是''int' ',所以

假设意外工作。另一方面,它应该有

假设printf()是一个普通的函数离子,而不是一个可变的,可能原则上会引起问题的


The correct return type of printf() happens to be ''int'', so that
assumption accidentally worked. On the other hand, it should have
assumed that printf() is an ordinary function, not a variadic one,
which could in principle cause problems.



返回类型无关紧要(除非,这可能是唯一的

问题)。一个varadic函数可能会以不同的方式取消函数调用所需的自动存储空间(实际上,我已经知道编译器这样做了b / b
)。它在编译器看来是一个整数函数

,它带有四个参数,但它不是:它是一个varadic函数

返回int,并且第一个element是一个字符指针。

The return type is irrelevant (unless, perhaps, that is the only
problem). A varadic function may unpile the automatic storage needed
for the function call differently (indeed, I have known compilers that
did this). It would appear to the compiler as an integer function
that takes four arguments but it isn''t: it is a varadic function
returning int, and for which the first element is a character pointer.


printf(c,34,c,34);
printf(c,34,c,34);


这篇关于基内斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆