Difference between revisions of "ANSI C"

From NetHackWiki
Jump to navigation Jump to search
m (fixed C++ link)
(Addition of C99 information)
Line 1: Line 1:
In computer programming, '''ANSI C''' (or ''ISO C'') is a specification for the [[Wikipedia:C programming language|C programming language]] and an update to the original K&R version of C. Programs written the ANSI C language have access to a few extra features inspired by [[Wikipedia:C plus plus|C++]]; the main difference between old C and ANSI C seems to be in declarations of function parameters. These days, ANSI C is routine and C programmers almost always use it.
+
In computer programming, '''ANSI C''' (or ''ISO C'', or ''C89'') is a specification for the [[Wikipedia:C programming language|C programming language]] and an update to the original K&R version of C. Programs written the ANSI C language have access to a few extra features inspired by [[Wikipedia:C plus plus|C++]]; the main difference between old C and ANSI C seems to be in declarations of function parameters. These days, ANSI C is routine and C programmers almost always use it.
 
* The Portland Pattern Repository [[wiki]] has a page: [[Wiki:AnsiCee]].
 
* The Portland Pattern Repository [[wiki]] has a page: [[Wiki:AnsiCee]].
 
* Wikipedia has one: [[Wikipedia:ANSI C]].
 
* Wikipedia has one: [[Wikipedia:ANSI C]].
Line 14: Line 14:
 
== Function declarations in ANSI C ==
 
== Function declarations in ANSI C ==
 
{{stub|Write about ANSI C function prototypes, NetHack's NDECL/FDECL/VDECL macros...}}
 
{{stub|Write about ANSI C function prototypes, NetHack's NDECL/FDECL/VDECL macros...}}
 +
 +
== Note for the ambitious newbie ==
 +
In case you consider creating a project of your own, be it a Rogue-like game or some other application, consider using a more powerful language than C. Nowadays there are lots of platform-independent, high-level alternatives like [[Wikipedia:Java (programming language)|Java]], [[Wikipedia:Python (programming language)|Python]] or [[Wikipedia:Perl|Perl]] just to mention a few. Such an application would
 +
be far easier to debug and maintain than its counterpart written in C. If you feel an urge to squeeze a bit more power out of the machine for your advanced ANSI-graphics and its pixelshading algorithms, at least consider using [[Wikipedia:C plus plus|C++]]. If you, despite every sane thought, decide that C is the language you want to use, use the latest version of C, [[Wikipedia:C (programming language)#C99|C99]]. The latest version contains
 +
many corrections and improvements and will cause you less trouble.
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 20:26, 28 September 2006

In computer programming, ANSI C (or ISO C, or C89) is a specification for the C programming language and an update to the original K&R version of C. Programs written the ANSI C language have access to a few extra features inspired by C++; the main difference between old C and ANSI C seems to be in declarations of function parameters. These days, ANSI C is routine and C programmers almost always use it.

However, NetHack was a very old program dating from before ANSI C's first spec in 1989. Today's version can take advantage of certain ANSI C features, and code for this is in tradstdc.h. Is NetHack written in ANSI C? Yes and no, depending on what tradstdc.h decides to do.

The "void" type

In C, the "void" type indicates a function that does not return a value. The original C did not have a "void" type; programmers often declared functions to return "int" and ignore the value. (This is why the compiler never complains if you forget to return a value from a non-void function.)

It became common to #define void int to cosmetically declare a void function. (The preprocessor would change every "void" to "int" and the C compiler would have no concept of void.) Later, many C compiler vendors started including the void keyword. C++ had a void keyword. So ANSI decided to put "void" in ANSI C.

If you find a void-free compiler to build NetHack with, then the procedure is to uncomment the #define NOVOID line at config.h#line239 so that tradstdc.h#line23 defines void.

Function declarations in ANSI C

This page is a stub. Should you wish to do so, you can contribute by expanding this page.

A user has suggested improving this page or section as follows:

"Write about ANSI C function prototypes, NetHack's NDECL/FDECL/VDECL macros..."

Note for the ambitious newbie

In case you consider creating a project of your own, be it a Rogue-like game or some other application, consider using a more powerful language than C. Nowadays there are lots of platform-independent, high-level alternatives like Java, Python or Perl just to mention a few. Such an application would be far easier to debug and maintain than its counterpart written in C. If you feel an urge to squeeze a bit more power out of the machine for your advanced ANSI-graphics and its pixelshading algorithms, at least consider using C++. If you, despite every sane thought, decide that C is the language you want to use, use the latest version of C, C99. The latest version contains many corrections and improvements and will cause you less trouble.