我出生之前C是什么样子的?

发布于 2024-08-05 19:05:51 字数 755 浏览 2 评论 0原文

这里有一个问题,C(K&RC)是什么样子的?问题是关于C生命的前十年或二十年?

我知道,我从我大学的一位教授那里听说,C 没有我们今天使用 ANSI C 获得的标准库。他们过去常常在包装汇编中编写 IO 例程!第二件事是 K&R 书,是程序员有史以来最好的书之一,这是我的教授告诉我们的:)

我想了解更多关于优秀的 ol' C 的信息。例如,你的主要区别是什么了解它与 ANSI C 相比,或者 C 如何改变程序员对编程的看法?


仅供记录,我主要在阅读这两篇论文后提出这个问题:

我知道它们是关于 C++ 的!这就是为什么我想更多地了解 C,因为这两篇论文是关于 C++ 如何从 C 中诞生的。我现在问的是之前的情况。感谢 Lazarus 指出 K&R 第一版,但我仍然渴望从 SO 大师那里了解更多有关 C 的信息;)

Here is the question, How did C (K&R C) look like? The question is about the first ten or twenty years of C's life?

I know, well I heard them from a prof in my uni, that C didn't have the standard libraries that we get with ANSI C today. They used to write IO routines in wrapped assembly! The second thing is that K&R book, is one the best books ever for a programmer to read, This is what my prof told us :)

I would like to know more about good ol' C. For example, what major difference you know about it compared to ANSI C, or how did C change programmers mind about programming?


Just for record, I am asking this question after reading mainly these two papers:

They are about C++, I know! thats why I wanna know more about C, because these two papers are about how C++ was born out of C. I am now asking about how it looked before that. Thanks Lazarus for pointing out to 1st edition of K&R, but I am still keen to know more about C from SO gurus ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

梦回梦里 2024-08-12 19:05:51

好吧,首先,没有任何函数原型垃圾。 main() 是这样声明的:

/* int */ main(c,v)
int c;
char *v[];
{
    /* Do something here. */
}

并且也没有任何花哨的双斜杠注释。也不枚举。真正的男人使用#define

啊,想起过去的美好时光,我热泪盈眶:-)

Well, for a start, there was none of that function prototype rubbish. main() was declared thus:

/* int */ main(c,v)
int c;
char *v[];
{
    /* Do something here. */
}

And there was none of that fancy double-slash comments either. Nor enumerations. Real men used #define.

Aah, brings a tear to my eyes, remembering the good old days :-)

哑剧 2024-08-12 19:05:51

查看 K&R 书籍的“主页”:贝尔实验室,特别是标题“语言的历史可追溯到 HOPL II 的《C 语言的发展》,1993 年”

Have a look at the 'home page' for the K&R book at Bell Labs, in particular the heading "The history of the language is traced in ``The Development of the C Language'', from HOPL II, 1993"

梦晓ヶ微光ヅ倾城 2024-08-12 19:05:51

从个人经验来看,我的前两个 C 编译器/开发环境是 DeSmet C(16 位 MS-DOS 命令行)和 Lattice C(也是 16 位 MS-DOS 命令行)。 DeSmet C 带有自己的文本编辑器 (see.exe) 和库 - 像 scr_rowcol() 这样的非标准函数定位光标。然而,即便如此,还是有一些标准函数,例如 printf()、fopen()、fread()、fwrite() 和 fclose()。

当时的一个有趣的特点是,你可以在四种基本记忆模型之间进行选择——S、P、D 和 L。多年来,其他变化不断出现,但这些是最重要的。 S 是“小型”模型,代码和数据均为 16 位寻址,每个寻址限制为 64K。 L 使用 24 位寻址,即一个 16 位段寄存器和一个 16 位偏移寄存器来计算地址,将地址空间限制为 1024K。当然,在 16 位 DOS 世界中,您受到 640K 的物理限制。 P和D是两种模式之间的折衷方案,其中P允许24位(640K)代码和64K数据,而D允许64K代码和640K数据寻址。

Speaking from personal experience, my first two C compilers/dev environments were DeSmet C (16-bit MS-DOS command line) and Lattice C (also 16-bit MS-DOS command line). DeSmet C came with its own text editor (see.exe) and libraries -- non-standard functions like scr_rowcol() positioned the cursor. Even then, however, there were certain functions that were standard, such as printf(), fopen() fread(), fwrite() and fclose().

One of the interesting peculiarities of the time was that you had a choice between four basic memory models -- S, P, D and L. Other variations came and went over the years, but these were the most significant. S was the "small" model, 16-bit addressing for both code and data, limiting you to 64K for each. L used 24-bit addressing, which was a 16-bit segment register and a 16-bit offset register to compute addresses, limiting you to 1024K of address space. Of course, in a 16-bit DOS world, you were confined to a physical limitation of 640K. P and D were compromises between the two modes, where P allowed for 24-bit (640K) code and 64K data, and D allowed for 64K code and 640K data addressing.

黎夕旧梦 2024-08-12 19:05:51

维基百科有关于此主题的一些信息

Wikipedia has some information on this topic.

水溶 2024-08-12 19:05:51

下面是使用 ANSI C 进行改进后的代码示例:

double GetSomeInfo(x)
int x;
{
    return (double)x / 2.0;
}

int PerformFabulousTrick(x, y, z)
int x, int y;
double z;
{
    /* here we go */
    z = GetSomeInfo(x, y); /* argument matching?  what's that? */
    return (int)z;
}

Here is one example of the code that changed with ANSI C for the better:

double GetSomeInfo(x)
int x;
{
    return (double)x / 2.0;
}

int PerformFabulousTrick(x, y, z)
int x, int y;
double z;
{
    /* here we go */
    z = GetSomeInfo(x, y); /* argument matching?  what's that? */
    return (int)z;
}
深空失忆 2024-08-12 19:05:51

我第一次在 1986 年开始在 VAX/VMS 上使用 C 语言。以下是我记得的差异:

  • 没有原型——函数定义和声明被写成
    int main() /* no void to specify empty parameter list */
    {
      void foo(); /* no parameter list in declaration */
      ...
    }
    ...
    void foo(x,y)
      int x;
      double y;
    {
      ...
    }
  • 没有泛型(void)指针类型;没有 原型。所有 *alloc() 函数都返回 char * (这就是为什么有些人仍然对 malloc() 的返回值进行强制转换的部分原因;对于 ANSI 之前的编译器,你必须);

  • 可变参数函数的处理方式不同;不需要任何固定参数,并且头文件的命名不同(varargs.h 而不是 stdarg.h);

  • 多年来,math.h 中添加了很多内容,尤其是在 C99 标准中; 80 年代的老式 C 并不是数值工作的最佳工具;

  • 图书馆没有标准化;几乎所有实现都有一个 stdio、math、string、ctype 等版本,但不同实现的内容不一定相同。

I first started working with C on VAX/VMS in 1986. Here are the differences I remember:

  • No prototypes -- function definitions and delcarations were written as
    int main() /* no void to specify empty parameter list */
    {
      void foo(); /* no parameter list in declaration */
      ...
    }
    ...
    void foo(x,y)
      int x;
      double y;
    {
      ...
    }
  • No generic (void) pointer type; all of the *alloc() functions returned char * instead (which is part of why some people still cast the return value of malloc(); with pre-ANSI compilers, you had to);

  • Variadic functions were handled differently; there was no requirement for any fixed arguments, and the header file was named differently (varargs.h instead of stdarg.h);

  • A lot of stuff has been added to math.h over the years, especially in the C99 standard; '80s-vintage C was not the greatest tool for numerical work;

  • The libraries weren't standardized; almost all implementations had a version of stdio, math, string, ctype, etc., but the contents were not necessarily the same across implementations.

愁杀 2024-08-12 19:05:51

看看版本 6 Unix 内核的代码 - 这就是 C 的样子!

请参阅 Lion 对 Unix 第六版的评论 (亚马逊)。

另外,如果您告诉我们您的年龄,事情会更容易 - 您的个人资料显示您 22 岁,因此您询问的是 1987 年之前的代码。

另请考虑:1984 年的 Unix 编程环境

Look at the code for the Version 6 Unix kernel - that was what C looked like!

See Lion's Commentary on Unix 6th Edition (Amazon).

Also, it would be easier if you told us your age - your profile says you're 22, so you're asking about code prior to 1987.

Also consider: The Unix Programming Environment from 1984.

又爬满兰若 2024-08-12 19:05:51

虽然出于显而易见的原因,核心语言出现在图书馆之前,但如果您拥有 K & R 于 1978 年发布,你会发现这个库非常熟悉。此外,C 最初用于 Unix 开发,并且该库与操作系统的 I/O 服务挂钩。所以我认为你教授的说法可能是杜撰的。

最明显的区别是定义函数的方式:

VOID* copy( dest, src, len )
    VOID* dest ;
    VOID* src ;
    int len ;
{
   ...
}

而不是:

void* copy( void* dest, void* src, int len )
{
    ... 
}

例如。注意VOID的使用; K&RC 没有 void 类型,通常 VOID 是定义为 int* 的宏。不用说,为了让它发挥作用,早期编译器中的类型检查是宽松的。从实践的角度来看,C 验证代码的能力很差(主要是由于缺乏函数原型和弱类型检查),因此诸如 lint 之类的工具很受欢迎。

1978 年,该语言的定义是 K&R 书。 1989年由ANSI标准化,后来由ISO标准化,第二版不再被视为语言定义,而是基于ANSI C。在我看来,它仍然是关于C的最好的书,总体上是一本很好的编程书籍。

维基百科上有一个简短的描述,可能会有所帮助。你最好的选择是获得 K&R 的第一版副本,但是,我不会用它来学习 C,而是获得第二版。为此。

While for obvious reasons the core language came before the library, if you get hold of a first edition copy of K & R published in 1978 you will find the library very familiar. Also C was originally used for Unix development, and the library hooked into the I/O services of the OS. So I think your prof's assertion is probably apocryphal.

The most obvious difference is the way functions were defined:

VOID* copy( dest, src, len )
    VOID* dest ;
    VOID* src ;
    int len ;
{
   ...
}

instead of:

void* copy( void* dest, void* src, int len )
{
    ... 
}

for example. Note the use of VOID; K&R C did not have a void type, and typically VOID was a macro defined as int*. Needless to say, to allow this to work, the type checking in early compilers was permissive. From a practical point of view, the ability of C to validate code was poor (largely through lack of function prototypes and weak type checking), and hence the popularity of tools such a lint.

In 1978 the definition of the language was the K&R book. In 1989 it was standardised by ANSI and later by ISO, the 2nd edition is no longer regarded as the language definition, and was based on ANSI C. It is still the best book on C IMO, and a good programming book in general.

There is a brief description on Wikipedia which may help. Your best bet is to get a first edition copy of K&R, however, I would not use it to learn C, get a 2nd ed. for that.

等风来 2024-08-12 19:05:51

我在 20 世纪 80 年代初开始使用 C。正如有人指出的那样,我现在看到的与当时的主要区别是早期的 C 语言没有函数原型。最早使用的 CI 拥有与今天几乎相同的标准库。如果说 C 语言没有 printf 或 fwrite 的某个时期,那是在我的时代之前!我从最初的 K&R 书中学习了 C。这确实是一个经典,证明了技术精湛的人也可以成为优秀的作家。我相信你可以在亚马逊上找到它。

I started using C in the early 1980's. The key difference I've seen between now and then was that early C did not have function prototypes, as someone noted. The earliest C I ever used had pretty much the same standard library as today. If there was a time when C didn't have printf or fwrite, that was before even my time! I learned C from the original K&R book. It is indeed a classic, and proof that technically sophisticated people can also be excellent writers. I'm sure you can find it on Amazon.

要走干脆点 2024-08-12 19:05:51

您可能会浏览一下您要查找的时间段内的混淆的 C 竞赛条目。

You might glance at the obfuscated C contest entries from the time period you are looking for.

习ぎ惯性依靠 2024-08-12 19:05:51

16 位整数在过去很常见。

16 bit integers were quite common in the ol' days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文