错误:重新说明没有联动 [英] Error : Redeclaration with no linkage

查看:474
本文介绍了错误:重新说明没有联动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
int x=13; // forcing space allocation 
int x; 
int main(){
  printf("%d\n",x); 
}

在code编译以上但低于一个没有。为什么?

The code above compiles but the one below does not. why ?

#include<stdio.h> 
int main(){
  int x=13; // forcing space allocation 
  int x;
  printf("%d\n",x); 
}

有人告诉我,INT X;可以由编译器为根据上下文的声明或定义PTED间$ P $。我可以看到,在第一种情况下(全球性),但在第二次发生了什么。

i was told that int x ; can be interpreted by the complier as a declaration or definition depending on the context . i can see that in the first case(global one) but what happens in the second.

推荐答案

<一个href=\"http://stackoverflow.com/questions/2068798/how-to-access-the-correct-global-variable-in-c/2068819#2068819\">Quoting:

您不能在C程序两个同名的全局变量。 C
  可能允许通过在同一个文件范围内多个定义
  <一href=\"http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03tentative_defn.htm\"相对=nofollow>暂定定义规则,但在任何情况下,所有定义将参考
  到相同的变量

You can't have two global variables with the same name in C program. C might allow multiple definitions in the same file scope through the tentative definition rule, but in any case all definitions will refer to the same variable.

这篇关于错误:重新说明没有联动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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