"&的extern QUOT;在一个街区内 [英] "extern" inside a block

查看:70
本文介绍了"&的extern QUOT;在一个街区内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在变量前面看到了一些带有extern修饰符的代码

在块内声明。这些纯粹的定义(没有定义)

或者它们是静态持续时间但外部联系的定义吗?


在常见问题解答或教程中没有多少。

I''ve seen some code with extern modifiers in front of variables
declared inside blocks. Are these purely definitions (no definition)
or are they definitions with static duration but external linkage?

Not much on this in the FAQ or tutorials.

推荐答案



G Patel写道:

G Patel wrote:
我见过一些在变量前面使用extern修饰符的代码
在块内声明。这些纯粹的定义(没有定义)


更正:纯粹的声明

或者它们是静态持续时间但外部联系的定义吗?
在FAQ或教程中没有太多内容。
I''ve seen some code with extern modifiers in front of variables
declared inside blocks. Are these purely definitions (no definition)
correction: purely declarations
or are they definitions with static duration but external linkage?

Not much on this in the FAQ or tutorials.









G Patel写道:


G Patel wrote:
G Patel写道:
G Patel wrote:
我看到一些代码在变量前面有外部修饰符
在块内声明。这些纯粹的定义(没有定义)
I''ve seen some code with extern modifiers in front of variables
declared inside blocks. Are these purely definitions (no definition)



更正:纯粹的声明


correction: purely declarations

或者它们是静态持续时间但外部联系的定义?

在FAQ或教程中没有太多内容。
or are they definitions with static duration but external linkage?

Not much on this in the FAQ or tutorials.




它们是对象或函数的声明

在其他地方定义了外部链接。 (恕我直言他们

也是风格上令人反感的,但这是另一个

讨论。)


-
Er*********@sun.com



They are declarations of objects or functions
defined elsewhere with external linkage. (IMHO they
are also stylistically repugnant, but that''s another
discussion.)

--
Er*********@sun.com


G Patel写道:
G Patel wrote:
我在块内声明的变量前面看到了一些带外部修饰符的代码。这些纯粹是[声明](没有定义)


是。

或者它们是静态持续时间但外部联系的定义吗?


No.

在常见问题解答或教程中没有太多内容。


不要惊慌。

很少有人要求这个。

当我想保持声明私密时我会使用它: br $>
cat main.c
I''ve seen some code with extern modifiers
in front of variables declared inside blocks.
Are these purely [declarations] (no definition)
Yes.
or are they definitions with static duration but external linkage?
No.
Not much on this in the FAQ or tutorials.
Not surpizing.
There is seldom call for this.
I use it when I want to keep declarations private:
cat main.c



#include< stdio.h>


int main(int argc,char * argv []){

extern void * malloc(size_t);

extern void free(void *);

const size_t n = 13;

int * p =(int *)malloc(n * sizeof(int));

free((void *)p);

返回0;

}


例如,当我想使用私人帮助函数时。


#include <stdio.h>

int main(int argc, char* argv[]) {
extern void* malloc(size_t);
extern void free(void*);
const size_t n = 13;
int* p = (int*)malloc(n*sizeof(int));
free((void*)p);
return 0;
}

When, for example, I want to use a private helper function.


这篇关于&QUOT;&的extern QUOT;在一个街区内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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