Content deleted Content added
Emperorbma (talk | contribs) m remove stray period |
Quuxplusone (talk | contribs) m →Examples: use <code> until <source> highlighting is fixed |
||
Line 2:
==Examples==
In programming languages without [[structured exception handling]] (e.g. in the [[C (programming language)|C programming language]]), ''error codes'' are often stored in [[global variable]]s with names
<
/* attempt to open file for reading */
FILE *fp = fopen("filename", "r");
/* if file cannot be opened, print error number and error string */
if (fp == NULL)
printf("Cannot open file, error %
</
Since error codes are typically global variables, they can be read or written from any portion of the program. As with other global variables, that ease of access can be a source of problems in a [[thread (computer science)|multithreaded]] environment, since the process global variables could be set by more than one thread, causing a [[race condition]]. To fix this problem, [[POSIX]] defines <code>errno</code> to be a [[thread-local]] variable.
|