Difference between revisions of "C"

From RogueBasin
Jump to navigation Jump to search
(Add some more, syntax/detail updates)
 
(20 intermediate revisions by 10 users not shown)
Line 1: Line 1:
== Background ==
== Background ==


The '''C programming language''' is a standardized imperative computer programming programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications. It is also commonly used in computer science education, despite not being designed for novices.
The '''C programming language''' is a standardized imperative computer programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages.
 
C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications. It is also commonly used in computer science education, despite not being designed for novices.


== Language Characteristics ==
== Language Characteristics ==


C is a relatively minimalist programming language that operates close to the hardware, and is more similar to [[assembly language]] than to most High-level programming languages.  
C is a relatively minimalist programming language that operates close to the hardware, and is closer to [[assembly language]] than to most modern high-level programming languages. Although, compared to assembly language, C can accurately be described as a "high-level" programming language, since C's features and syntax abstracts away much of the work that would need to be done if writing the same program in assembly.


C was created with one important goal in mind: to make it easier to write large programs with fewer errors in the procedural programming paradigm, but without putting a burden on the writer of the C compiler, who is encumbered by complex language features. To this end, C has the following important features:
C was created with one important goal in mind: to make it easier to write large programs with fewer errors in the procedural programming paradigm, but without putting a burden on the writer of the C compiler, who is encumbered by complex language features. To this end, C has the following important features:
Line 19: Line 21:
* Lexical variable scoping  
* Lexical variable scoping  
* Records, or user-defined aggregate datatypes (structs) which allow related data to be combined and manipulated as a whole
* Records, or user-defined aggregate datatypes (structs) which allow related data to be combined and manipulated as a whole
* Portability, in the strict sense that standards-compliant and portably written C programs can be compiled for a very wide variety of computer platforms and operating systems with little or no change to its source code


Some features that C lacks that are found in other languages include:
Some features that C lacks that are found in other languages include:
Line 26: Line 29:
* An advanced type system
* An advanced type system
* Closures
* Closures
* Generic programming
* Generic programming (added in C11)
* Operator overloading
* Operator overloading
* Native support for multithreading and networking
* Native support for multithreading and networking (C11 adds concurrency support)


== Roguelike Issues ==
== Roguelike Issues ==


A lot of RLs actually use "C++/--", which is basic C with some of the more useful [[C++]|[Cpp]] features. This list applies to those using strict ANSI C.
A lot of RLs actually use "C++/--", which is basic C with some of the more useful [[Cpp|C++]] features. This list applies to those using strict C features such as ANSI C (aka C89/C90), or later revisions of the C standard such as C99, C11, C18, or C23.


Pros:
Pros:
* C is highly portable
* C compilers exist for almost every platform, and it is possible to write highly portable C code that runs almost everywhere.
* There are lots of open-source C RLs (so there are many examples)
* There are lots of open-source C RLs, so there are many examples.
* C is fast
* Because of its low-level nature, C has little built-in overhead which means it is a good choice if you program for platforms with limited resources.
* Interfaces exist for many graphics libraries
* Interfaces exist for many graphics libraries.
* Lots of people have made successful RLs in C, so you can too!
* Lots of people have made successful RLs in C, so you can too!


Cons:
Cons:
* Lack of garbage collection means handling memory allocation by hand
* C is designed for the structured, procedural programming paradigm. It is not a good choice if you want to use object-oriented programming techniques, although function pointers and void pointers make it possible to construct your own object-oriented system.
* Lack of classes makes it hard to do an object-oriented design, limiting project flexibility (so you have to plan ahead)
* C is a bare-bones, low-level language with no built-in support for modern conveniences of high-level languages like garbage collection or XML handling, though libraries exist for many features.
* Basically you are using a 30 year old language and sometimes that shows when you reach for more advanced language features like generics, XML handling, or thread synchronization. 3rd party libraries exist to augment the language and overcome these shortfallings.


== C Roguelikes ==
== C Roguelikes ==


C is the default language for roguelike development. There are a vast number of C roguelikes.
Being the default language for roguelike development in the early days of the genre, many of the "traditional" major roguelikes are written in C:
 
* [[Rogue]] (1980)
* [[Super-Rogue]] (1983)
* [[Hack]] (1984)
* [[Larn]] (1986)
* [[Rogue Clone]] (1986)
* [[NetHack]] (1987)
* [[Moria | Umoria]] (1988)
* [[Omega]] (1980s)
* [[Angband]] (1990)
* [[Ularn]] (1992)
* [[ADOM]] (1994)
* [[QHack]] (1997)
 
These days it's much more common for a roguelike to be written in [[Python]] or [[C++]], however some 21st century roguelikes are still written in C:
 
* [[Martin's Dungeon Bash]] (2005)
* [[Scrap]] (2005)
* [[2DRL in 2K]] (2006)
* [http://locklessinc.com/articles/512byte_roguelike/ A Roguelike in less than 512 Bytes] (2006)
* [[Alan's Psychedelic Journey]] (2008)
* [[CryptRover]] (2008)
* [[Brogue]] (2009)
* [[Chickhack]] (2009)
* [[NLarn]] (2009)
* [[Tomb of Rawdin]] (2009)
* [[UnNetHack]] (2009)
* [[Warp Rogue]] (2009)
* [[HackOfLife]] (2010)
* [[Last-of-candle]] (2010)
* [[Daedlyflazh]] (2011)
* [[Free-Like]] (2011)
* [[Rook]] (2011)
* [[Regicide]] (2011)
* [[RevivedHack]] (2011)
* [[Zerogue]] (2011)
* [[Ascension of the Drillworms]] (2012)
* [[Cave Chop]] (2012)
* [[DynaHack]] (2012)
* [[NitroHack]] (2012)
* [[Sil]] (2012)
* [[UnBrogue]] (2012)
* [[Classic Rogue]] (2013)
* [[CoreRL]] (2013)
* [[Kunoichi]] (2014)
* [[Rouge]] (2014)
* [[XLarn]] (2015)
* [[Roguemare]] (2017)
* [[Tangaria]] (2019)
* [[Brogue Community Edition]] (2020)
* [[Roglik]] (2022)


* [[Nethack]]
Many traditional C roguelikes tended to use the [[Curses]] library, however there are C bindings for [[Libtcod|libtcod]]. Another modern choice may be [[SDL]] perhaps using a [https://dwarffortresswiki.org/Tileset_repository Dwarf Fortress Tileset] or [[SDL_ttf]] to render characters.
* [[Angband]]


== Related Links ==
== Related Links ==


[[Category:Programming languages]]
[[Category:Programming languages]]

Latest revision as of 11:12, 26 June 2024

Background

The C programming language is a standardized imperative computer programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages.

C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications. It is also commonly used in computer science education, despite not being designed for novices.

Language Characteristics

C is a relatively minimalist programming language that operates close to the hardware, and is closer to assembly language than to most modern high-level programming languages. Although, compared to assembly language, C can accurately be described as a "high-level" programming language, since C's features and syntax abstracts away much of the work that would need to be done if writing the same program in assembly.

C was created with one important goal in mind: to make it easier to write large programs with fewer errors in the procedural programming paradigm, but without putting a burden on the writer of the C compiler, who is encumbered by complex language features. To this end, C has the following important features:

  • A simple core language, with important functionality such as math functions or file handling provided by sets of library routines instead
  • Focus on the procedural programming paradigm, with facilities for programming in a structured style
  • A simple type system which prevents many operations that are not meaningful
  • Use of a preprocessor language, the C preprocessor, for tasks such as defining macros and including multiple source files
  • Low-level unchecked access to computer memory via the use of pointers
  • A minimalistic set of keywords
  • Parameters that are always passed to functions by value, never by reference
  • Function pointers, which allow for a rudimentary form of Closure and Polymorphism
  • Lexical variable scoping
  • Records, or user-defined aggregate datatypes (structs) which allow related data to be combined and manipulated as a whole
  • Portability, in the strict sense that standards-compliant and portably written C programs can be compiled for a very wide variety of computer platforms and operating systems with little or no change to its source code

Some features that C lacks that are found in other languages include:

  • Type safety
  • Garbage collection
  • Classes or objects
  • An advanced type system
  • Closures
  • Generic programming (added in C11)
  • Operator overloading
  • Native support for multithreading and networking (C11 adds concurrency support)

Roguelike Issues

A lot of RLs actually use "C++/--", which is basic C with some of the more useful C++ features. This list applies to those using strict C features such as ANSI C (aka C89/C90), or later revisions of the C standard such as C99, C11, C18, or C23.

Pros:

  • C compilers exist for almost every platform, and it is possible to write highly portable C code that runs almost everywhere.
  • There are lots of open-source C RLs, so there are many examples.
  • Because of its low-level nature, C has little built-in overhead which means it is a good choice if you program for platforms with limited resources.
  • Interfaces exist for many graphics libraries.
  • Lots of people have made successful RLs in C, so you can too!

Cons:

  • C is designed for the structured, procedural programming paradigm. It is not a good choice if you want to use object-oriented programming techniques, although function pointers and void pointers make it possible to construct your own object-oriented system.
  • C is a bare-bones, low-level language with no built-in support for modern conveniences of high-level languages like garbage collection or XML handling, though libraries exist for many features.

C Roguelikes

Being the default language for roguelike development in the early days of the genre, many of the "traditional" major roguelikes are written in C:

These days it's much more common for a roguelike to be written in Python or C++, however some 21st century roguelikes are still written in C:

Many traditional C roguelikes tended to use the Curses library, however there are C bindings for libtcod. Another modern choice may be SDL perhaps using a Dwarf Fortress Tileset or SDL_ttf to render characters.

Related Links