Update assert.h

This commit is contained in:
bumbread 2022-07-30 13:06:35 +11:00
parent 0ab396ffc9
commit d889bebc4e
4 changed files with 43 additions and 267 deletions

View File

@ -10,26 +10,25 @@ Macro definitions:
Assert a given condition is true, otherwise abort execution of a program. Assert a given condition is true, otherwise abort execution of a program.
<details><summary>Description</summary>
The macro checks whether `expr` is true, and if not, prints the The macro checks whether `expr` is true, and if not, prints the
information about where the error occurs and then aborts execution in a way diagnostic information and then aborts execution in a way equivalent to calling
equivalent to calling abort() function (See SIGABRT). abort() function (See SIGABRT).
You can disable the assertion checks by defining NDEBUG macro. If DEBUG macro is defined, assert does not print a diagnostic message, and
instead simply causes a debug break.
</details> If NDEBUG macro is defined assert expands to an empty statement. If both NDEBUG
and DEBUG are defined, then DEBUG macro is ignored.
<details><summary>Declaration</summary>
```c ```c
#if defined(NDEBUG) #if defined(NDEBUG)
#define assert(expr) ((void)0) #define assert(expr) ((void)0)
#elif defined(DEBUG)
#define assert(expr) /* debug break */
#else #else
#define assert(expr) /* see description */ #define assert(expr) /* print diagnostic, then abort */
#endif #endif
``` ```
</details>
<details> <details>
<summary>Example</summary> <summary>Example</summary>
@ -74,11 +73,6 @@ Trace:
Keyword macro that expands to C11 keyword `_Static_assert`. Keyword macro that expands to C11 keyword `_Static_assert`.
<details>
<summary>Definition</summary>
```c ```c
#define static_assert _Static_assert #define static_assert _Static_assert
``` ```
</details>

View File

@ -1,252 +0,0 @@
# ctype.h - Classification of ASCII characters
Function declarations:
- [isalnum](#isalnum)
- [isalpha](#isalpha)
- [isblank](#isblank)
- [iscntrl](#iscntrl)
- [isdigit](#isdigit)
- [isgraph](#isgraph)
- [islower](#islower)
- [isprint](#isprint)
- [ispunct](#ispunct)
- [isspace](#isspace)
- [isupper](#isupper)
- [isxdigit](#isxdigit)
- [tolower](#tolower)
- [toupper](#toupper)
## [isalnum](#isalnum)
<details><summary>Description</summary>
Function checks whether given integer is an ASCII code representing a letter or
a digit. These characters are lowercase letters ('a'..'z'), uppercase letters
('A'..'Z') and digits ('0'..'9').
</details>
<details><summary>Declaration</summary>
```c
int isalnum(int c);
```
</details>
## [isalpha](#isalpha)
<details><summary>Description</summary>
Function checks whether given integer is an ASCII code representing a letter.
These characters are lowercase letters ('a'..'z') and uppercase letters.
</details>
<details><summary>Declaration</summary>
```c
int isalpha(int c);
```
</details>
## [isblank](#isblank)
<details><summary>Description</summary>
Checks whether a character is a space (' ') or a horizontal tab ('\t')
</details>
<details><summary>Declaration</summary>
```c
int isblank(int c);
```
</details>
## [iscntrl](#iscntrl)
<details><summary>Description</summary>
Checks whether a character is a control character
('\x00' through '\x1f' and '\x7f').
</details>
<details><summary>Declaration</summary>
```c
int iscntrl(int c);
```
</details>
## [isdigit](#isdigit)
<details><summary>Description</summary>
Checks whether a character is a digit ('0' through '9')
</details>
<details><summary>Declaration</summary>
```c
int isdigit(int c);
```
</details>
## [isxdigit](#isxdigit)
<details><summary>Description</summary>
Checks whether a character is a hexadecimal digit ('0' through '9', 'a' through 'f' or 'A' through 'F')
</details>
<details><summary>Declaration</summary>
```c
int isxdigit(int c);
```
</details>
## [isgraph](#isgraph)
<details><summary>Description</summary>
Checks whether a character is a
- Number;
- Letter;
- or punctuation
</details>
<details><summary>Declaration</summary>
```c
int isgraph(int c);
```
</details>
## [islower](#islower)
<details><summary>Description</summary>
Checks whether a character is a lowercase letter ('a' through 'z')
</details>
<details><summary>Declaration</summary>
```c
int islower(int c);
```
</details>
## [isupper](#isupper)
<details><summary>Description</summary>
Checks whether a character is a uppercase letter ('A' through 'Z')
</details>
<details><summary>Declaration</summary>
```c
int islower(int c);
```
</details>
## [isprint](#isprint)
<details><summary>Description</summary>
Checks whether a character is a
- Number;
- Letter;
- Space;
- or punctuation
</details>
<details><summary>Declaration</summary>
```c
int isprint(int c);
```
</details>
## [ispunct](#ispunct)
<details><summary>Description</summary>
Checks whether a character is a punctuation character (one of `!"#$%&'()*+,-./:;<=>?@[\]^_{|}~`
or backtick).
</details>
<details><summary>Declaration</summary>
```c
int ispunct(int c);
```
</details>
## [isspace](#isspace)
<details><summary>Description</summary>
Function checks whether given integer is a whitespace character. These
characters include whitespace (' '), form feed ('\f'), line feed ('\n'),
carriage return ('\r'), horizontal and vertical tab ('\t' and '\v').
</details>
<details><summary>Declaration</summary>
```c
int isspace(int c);
```
</details>
## [tolower](#tolower)
<details><summary>Description</summary>
If the character is an uppercase letter returns lowercase version of it. Otherwise
returns the character unmodified.
</details>
<details><summary>Declaration</summary>
```c
int tolower(int c);
```
</details>
## [toupper](#toupper)
<details><summary>Description</summary>
If the character is an lowercase letter returns uppercase version of it. Otherwise
returns the character unmodified.
</details>
<details><summary>Declaration</summary>
```c
int toupper(int c);
```
</details>

View File

@ -14,6 +14,17 @@ void _Noreturn _assert(
#if defined(NDEBUG) #if defined(NDEBUG)
#define assert(ignore) ((void)0) #define assert(ignore) ((void)0)
#elif defined(DEBUG)
#if __GNUC__
#define assert(c) if (!(c)) __builtin_trap()
#elif _MSC_VER
#define assert(c) if (!(c)) __debugbreak()
// TODO: Handle Cuik, and if such handling is not required remove this comment
#else
// In debug mode there shouldn't be any optimizations so this should
// work as a simple way to cause a trap.
#define assert(c) if (!(c)) *(volatile int *)0 = 0
#endif
#else #else
#define _static_assert _Static_assert #define _static_assert _Static_assert
#define assert(condition) \ #define assert(condition) \

23
inc/std.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <inttypes.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <threads.h>
#include <time.h>
#include <uchar.h>
#include <wchar.h>
#include <wctype.h>