Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C character classification
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Implementation == For performance, the standard character classification functions are usually implemented as macros instead of [[function (programming)|functions]]. But, due to limitations of macro evaluation, they are generally not implemented today as they were in early versions of [[Linux]] like: <syntaxhighlight lang="c"> #define isdigit(c) ((c) >= '0' && (c) <= '9') </syntaxhighlight> This can lead to an error when the macro parameter <code>x</code> is expanded to an expression with a [[Side effect (computer science)|side effect]]; for example: <code>isdigit(x++)</code>. If the implementation was a function, then x would be incremented only once. But for this macro definition it is incremented twice. To eliminate this problem, a common implementation is for the macro to use table lookup. For example, the standard library provides an array of 256 integers {{endash}} one for each character value {{endash}} that each contain a bit-field for each supported classification. A macro references an integer by character value index and accesses the associated bit-field. For example, if the low bit indicates whether the character is a digit, then the <code>isdigit</code> macro could be written as: <syntaxhighlight lang="c"> #define isdigit(c) (TABLE[c] & 1) </syntaxhighlight> The macro argument, <code>c</code>, is referenced only once, so is evaluated only once.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)