缺少功能定义需要诊断吗? [英] Diagnostic required for missing function definition?

查看:61
本文介绍了缺少功能定义需要诊断吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下程序是否需要诊断?该标准的哪一部分

处理此问题? (我阅读了关于功能的部分

来电并没有看到任何内容。)


void f(无效);

int main(void){f(); }


如果函数声明是,答案仍然是相同的:

static void f(void);

Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn''t see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);

推荐答案

老狼说:
Old Wolf said:

以下程序是否需要诊断?该标准的哪一部分

处理此问题? (我阅读了关于功能的部分

来电并没有看到任何内容。)


void f(无效);

int main(void){f(); }
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn''t see anything).

void f(void);

int main(void) { f(); }



无需诊断消息。对于所有编译器都知道,f()的

定义在另一个翻译单元中。但是如果它不是,那么显然你会得到一个链接器错误。

No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn''t,
you''ll get a linker error, obviously.


答案是否仍然相同如果函数声明是:

static void f(void);
Is the answer still the same if the function declaration was:
static void f(void);



优秀的问题。据我所知,对于诊断消息仍然没有要求

(虽然当然实现是免费的

,如果这样做的话,提供一个) ,但我很容易出错。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

Excellent question. As far as I can tell, there is still no requirement
for a diagnostic message (although of course the implementation is free
to provide one if it feels like so doing), but I could easily be wrong.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


在文章< Yv ******* **************@bt.com>,

Richard Heathfield< rj*@see.sig.invalidwrote:
In article <Yv*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:

> Old Wolf说:
>Old Wolf said:

>以下程序是否需要诊断?该标准的哪一部分涉及此问题? (我阅读了关于函数
调用的部分并没有看到任何内容。)

void f(void);

int main(void){f (); }
>Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn''t see anything).

void f(void);

int main(void) { f(); }


不需要诊断消息。对于所有编译器都知道,f()的定义是在另一个翻译单元中。但是,如果它不是,那么显然会发现链接器错误。


No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn''t,
you''ll get a linker error, obviously.



不是实现的链接器部分吗?因此,如果需要链接器错误

,那就意味着整个实现必须发出

a诊断。


N869 6.9说:

[#5]外部定义是外部声明,

也是函数或对象的定义。如果在

表达式中使用了使用外部链接声明的

标识符(除了作为sizeof

运算符的操作数的一部分),在整个程序的某个地方,应该有

标识符的一个外部定义;

否则,不应该超过一个.127)


这是* not *在一个Constraints部分,所以它看起来像是'

未定义的行为和实现(在这种情况下是链接器)是允许的

默默地接受它或者默默地拒绝生成可执行文件。


(这对我来说似乎是合理的。考虑这个源文件代表

a完成程序:

--------

void read(void);

int main(void){read();返回0;}

--------

我会惊讶地发现Unix托管的C实现失败

编译这个,但可执行文件可能会或可能不会表现敏感bly。)

Isn''t the linker part of the implementation? So if a linker error
is required, that would mean the implementation as a whole must issue
a diagnostic.

N869 6.9 says:
[#5] An external definition is an external declaration that
is also a definition of a function or an object. If an
identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof
operator), somewhere in the entire program there shall be
exactly one external definition for the identifier;
otherwise, there shall be no more than one.127)

This is *not* in a Constraints section, so it looks to me like it''s
undefined behavior and the implementation (linker in this case) is allowed
to silently accept it or silently refuse to generate an executable.

(This seems reasonable to me. Consider this source file representing
a complete program:
--------
void read(void);
int main(void) { read(); return 0; }
--------
I would be surprised to find a Unix-hosted C implementation that fails
to compile this, but the executable may or may not behave sensibly.)


>如果函数声明是:
static,答案是否仍然相同void f(void);
>Is the answer still the same if the function declaration was:
static void f(void);


非常好的问题。据我所知,对于诊断消息仍然没有要求(虽然当然可以免费实现提供一个,如果感觉这样做),但我很容易出错。


Excellent question. As far as I can tell, there is still no requirement
for a diagnostic message (although of course the implementation is free
to provide one if it feels like so doing), but I could easily be wrong.



N869 6.9#3(其中*是*在约束条款中)说:

此外,如果用

内部链接用在一个表达式中(除了作为sizeof运算符的操作数的一部分的

),应该是

一个外部定义

翻译单元中的标识符。


我不认为只是原型是外部定义。在#5中定义了

,所以在我看来,使用一个函数(或其他对象)

声明为static而未在该翻译单元中定义是一个约束

违规。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca


奇怪,那。我的程序不会让我的计算机系统崩溃。

- comp.lang.c中的理查德希思菲尔德

N869 6.9#3 (which *is* in a Constraints section) says:
Moreover, if an identifier declared with
internal linkage is used in an expression (other than as a
part of the operand of a sizeof operator), there shall be
exactly one external definition for the identifier in the
translation unit.

I don''t think just a prototype is an "external definition" as defined
in #5, so it looks to me like using a function (or other object) that is
declared static and not defined in that translation unit is a constraint
violation.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca

Odd, that. My programs don''t tend to make my computer systems fall over.
--Richard Heathfield in comp.lang.c


Old Wolf aécrit:
Old Wolf a écrit :

以下程序是否需要诊断?该标准的哪一部分

处理此问题? (我阅读了关于功能的部分

来电并没有看到任何内容。)


void f(无效);

int main(void){f(); }


如果函数声明为:答案仍然是相同的:

static void f(void);
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn''t see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);



根据我的要求,不需要诊断


main()有隐式结果(零)所以没有明确的

结果没问题。

No diagnostic is required, as far as I see

main() has an implicit result (zero) so the absence of an explicit
result is OK.


这篇关于缺少功能定义需要诊断吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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