是否可以找到将strcpy的当前语法添加到C标准的时间? [英] Is it possible to find out when the current syntax of strcpy was added to the C standard?

查看:233
本文介绍了是否可以找到将strcpy的当前语法添加到C标准的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最早公开可用的C标准似乎是1999年发布的ISO/IEC 9899:1999. strcpy函数已经具有其当前语法.

The oldest publicly available C standard seems to be the ISO/IEC 9899:1999, published in 1999. There the strcpy function already has its current syntax.

我问这个问题的原因是,我发现了一个非常古老的系统,其中(<令我震惊的是)strcpy的语法几乎与memcpy相同.

The reason I ask it is that I found a really, really old system where (to my greatest shock) strcpy seems to have almost the same syntax as memcpy.

在这种实现中,strcpy的行为如下:

In that implementiation strcpy behaves like this:

  • strcpy(char *destination, char *source, int length)的工作方式与现代的memcpy
  • strcpy(char *destination, char *source)确实可以编译,但是没有任何明显的副作用,就像使用length = 0调用它一样.
  • strncpy的工作原理与strcpy完全相同,甚至可以仅使用2个参数进行编译.
  • strcpy(char *destination, char *source, int length) works just like the modern memcpy
  • strcpy(char *destination, char *source) does compile, but it doesn't have any noticeable side-effect, just as if it was called with length = 0.
  • strncpy works exactly just like strcpy, it even compiles with just 2 parameters.

因此,对于对C考古学感兴趣(并且可以使用非常古老的标准)的人,是否存在未定义strcpy的C标准?定义哪个第一个标准?我要处理的是非标准的编译器(甚至不符合最旧的C标准的编译器)吗?

So, for someone interested in C-archeology (and having access to very old standards), was there a C standard where strcpy was not defined? Which was the first standard where it was defined? Am I dealing with a non-standard conforming compiler (a compiler that doesn't even conform to the oldest C standard)?

我找不到任何迹象表明应该真正实现哪个版本的C,唯一的提示是它是在1997年之前为富士通处理器编写的(因为我发现文字为"Copyright 1997").

I couldn't find any indication which version of C is really supposed to be implemented, the only hint is that it was written before 1997 (as I found the text "Copyright 1997") for a Fujitsu processor.

编辑:如果此来源是值得信赖的,strcpy已经在1989年以其当前形式定义.所以我必须处理比我最初怀疑的还要古老的东西!

If this source is to be trusted, strcpy was already defined in its current form already in 1989. So I have to deal with something even older than I first suspected!

推荐答案

C的第一个发布标准是C89(ANSI X3.159-1989).它对strcpy的定义如下:

The first published standard for C was C89 (ANSI X3.159-1989). It defined strcpy as follows:

char *strcpy(char *s1, const char *s2);

在此之前,请尝试寻找Kernighan和Ritchie编写的"The C Programming Language"的第一个版本,它是1978年至1989年发布时的事实上的标准.

Before, that, try looking for the first version of "The C Programming Language" by Kernighan and Ritchie, which was the de facto standard from its publication in 1978 to 1989. I would not be surprised if strcpy predates this.

根据 http://cm.bell-labs.com/7thEdMan/, 1979年发布的第7版UNIX将strcpy定义为

According to http://cm.bell-labs.com/7thEdMan/, Version 7 UNIX, released in 1979, defined strcpy as

char *strcpy(s1, s2)
char *s1, *s2;

我无法在1975年发布的UNIX版本6的文档中找到strcpy,但是由Dennis Ritchie编写的"C手册"中包含示例函数

I wasn't able to find strcpy in the documentation for Version 6 UNIX, which was released in 1975, but its "C Manual", written by Dennis Ritchie, contained an example function

copy(s1, s2)
char *s1, *s2
{
    while(*s2++ = *s1++);
}

Brian Kernighan编写的"C教程"包含以下版本:

Its "C Tutorial", written by Brian Kernighan, instead contained this version:

strcopy(s1, s2)
char s1[ ], s2[ ]; {
    int i;
    for( i = 0; (s2[i] = s1[i]) != '\0'; i++ );
}

这表明strcpy的现代版本起源于1975年V6 UNIX的发布与1978年K& R C的发布之间.

This suggests that the modern version of strcpy originated somewhere between the release of V6 UNIX in 1975 and the publication of K&R C in 1978.

请注意,即使在早期,我们也已经看到C的两个主要作者之间的风格差异:Kernighan将函数的开括号与参数声明放在同一行,而Ritchie则倾向于将其放在新行上本身.

Notice that even at this early time, we already see stylistic differences between the two principle authors of C: Kernighan put the opening bracket of functions on the same line as the parameter declaration, while Ritchie preferred to put it on a new line by itself.

这篇关于是否可以找到将strcpy的当前语法添加到C标准的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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