<wctype.h> Phân Loại và Biến Đổi Wide Character| Hàm | Mô tả |
|---|---|
iswalnum() |
Kiểm tra wide character có là chữ cái hoặc chữ số. |
iswalpha() |
Kiểm tra wide character có là chữ cái |
iswblank() |
Kiểm tra đây có phải wide blank character |
iswcntrl() |
Kiểm tra đây có phải wide control character. |
iswctype() |
Xác định phân loại wide character |
iswdigit() |
Kiểm tra wide character có là chữ số |
iswgraph() |
Kiểm tra wide character có in được mà không phải space |
iswlower() |
Kiểm tra wide character có là chữ thường |
iswprint() |
Kiểm tra wide character có in được |
iswpunct() |
Kiểm tra wide character có là dấu câu |
iswspace() |
Kiểm tra wide character có là whitespace |
iswupper() |
Kiểm tra wide character có là chữ hoa |
iswxdigit() |
Kiểm tra wide character có là chữ số hex |
towctrans() |
Chuyển wide character sang chữ hoa hoặc chữ thường |
towlower() |
Chuyển wide character hoa sang chữ thường |
towupper() |
Chuyển wide character thường sang chữ hoa |
wctrans() |
Hàm phụ trợ cho towctrans() |
wctype() |
Hàm phụ trợ cho iswctype() |
Cái này giống <ctype.h> nhưng dành cho wide character (ký tự rộng).
Với nó bạn có thể kiểm tra phân loại ký tự (kiểu “ký tự này có phải whitespace không?”) hoặc làm vài chuyển đổi ký tự cơ bản (kiểu “ép ký tự này thành chữ thường”).
iswalnum()Kiểm tra wide character có là chữ cái hoặc chữ số.
#include <wctype.h>
int iswalnum(wint_t wc);Về cơ bản là kiểm tra xem một ký tự có là chữ cái (A-Z hoặc a-z) hoặc chữ số (0-9). Nhưng vài ký tự khác cũng có thể tính là hợp lệ tùy theo locale.
Cái này tương đương với việc kiểm tra iswalpha() hoặc iswdigit() có true không.
Trả về true nếu ký tự là chữ cái hoặc chữ số.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswalnum(L'a')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswalnum(L'B')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswalnum(L'5')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswalnum(L'?')? L"yes": L"no"); // no
}iswalpha(), iswdigit(), isalnum()
iswalpha()Kiểm tra wide character có là chữ cái
#include <wctype.h>
int iswalpha(wint_t wc);Về cơ bản là kiểm tra một ký tự có là chữ cái (A-Z hoặc a-z). Nhưng vài ký tự khác cũng có thể tính là hợp lệ tùy theo locale. (Nếu ký tự khác được tính, chúng sẽ không phải ký tự điều khiển, chữ số, dấu câu hay space.)
Cái này giống như kiểm tra iswupper() hoặc iswlower().
Trả về true nếu ký tự là chữ cái.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswalpha(L'a')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswalpha(L'B')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswalpha(L'5')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswalpha(L'?')? L"yes": L"no"); // no
}iswblank()Kiểm tra đây có phải wide blank character
#include <wctype.h>
int iswblank(wint_t wc);Blank character là whitespace đồng thời được dùng làm dấu ngăn từ trên cùng một dòng. Ở locale “C”, các blank character duy nhất là space và tab.
Các locale khác có thể định nghĩa blank character khác.
Trả về true nếu đây là blank character.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswblank(L' ')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswblank(L'\t')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswblank(L'\n')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswblank(L'a')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswblank(L'?')? L"yes": L"no"); // no
}iswcntrl()Kiểm tra đây có phải wide control character.
#include <wctype.h>
int iswcntrl(wint_t wc);Spec khá trống trải ở chỗ này. Nhưng tôi cứ giả định là nó hoạt động giống bản không-wide. Vậy thì xem bản kia.
Control character (ký tự điều khiển) là ký tự không in được, phụ thuộc locale.
Với locale “C”, nghĩa là control character nằm trong khoảng 0x00 đến 0x1F (ngay trước ký tự SPACE) và 0x7F (ký tự DEL).
Về cơ bản nếu không phải ký tự ASCII in được (hoặc Unicode nhỏ hơn 128), thì đó là control character trong locale “C”.
Chắc là vậy.
Trả về true nếu đây là control character.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswcntrl(L'\t')? L"yes": L"no"); // yes (tab)
wprintf(L"%ls\n", iswcntrl(L'\n')? L"yes": L"no"); // yes (newline)
wprintf(L"%ls\n", iswcntrl(L'\r')? L"yes": L"no"); // yes (return)
wprintf(L"%ls\n", iswcntrl(L'\a')? L"yes": L"no"); // yes (bell)
wprintf(L"%ls\n", iswcntrl(L' ')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswcntrl(L'a')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswcntrl(L'?')? L"yes": L"no"); // no
}iswdigit()Kiểm tra wide character có là chữ số
#include <wctype.h>
int iswdigit(wint_t wc);Kiểm tra wide character có là chữ số (0-9).
Trả về true nếu ký tự là chữ số.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswdigit(L'0')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswdigit(L'5')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswdigit(L'a')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswdigit(L'B')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswdigit(L'?')? L"yes": L"no"); // no
}iswgraph()Kiểm tra wide character có in được mà không phải space
#include <wctype.h>
int iswgraph(wint_t wc);Trả về true nếu đây là ký tự in được (không phải control) và cũng không phải whitespace.
Về cơ bản nếu iswprint() true và iswspace() false.
Trả về true nếu đây là ký tự in được mà không phải space.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswgraph(L'0')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswgraph(L'a')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswgraph(L'B')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswgraph(L'?')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswgraph(L' ')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswgraph(L'\n')? L"yes": L"no"); // no
}iswprint(), iswspace(), isgraph()
iswlower()Kiểm tra wide character có là chữ thường
#include <wctype.h>
int iswlower(wint_t wc);Kiểm tra một ký tự có là chữ thường, trong khoảng a-z.
Ở các locale khác, có thể có ký tự chữ thường khác. Trong mọi trường hợp, để là chữ thường thì những điều sau phải đúng:
!iswcntrl(c) && !iswdigit(c) && !iswpunct(c) && !iswspace(c)Trả về true nếu wide character là chữ thường.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswlower(L'c')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswlower(L'0')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswlower(L'B')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswlower(L'?')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswlower(L' ')? L"yes": L"no"); // no
}islower(), iswupper(), iswalpha(), towupper(), towlower()
iswprint()Kiểm tra wide character có in được
#include <wctype.h>
int iswprint(wint_t wc);Kiểm tra wide character có in được, bao gồm cả space (' '). Nên giống như isgraph(), chỉ khác là space không bị bỏ rơi ngoài trời lạnh.
Trả về true nếu wide character in được, bao gồm cả space (' ').
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswprint(L'c')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswprint(L'0')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswprint(L' ')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswprint(L'\r')? L"yes": L"no"); // no
}isprint(), iswgraph(), iswcntrl()
iswpunct()Kiểm tra wide character có là dấu câu
#include <wctype.h>
int iswpunct(wint_t wc);Kiểm tra wide character có là dấu câu.
Ở bất kỳ locale nào, điều này có nghĩa là:
!isspace(c) && !isalnum(c)True nếu wide character là dấu câu.
Kết quả có thể khác nhau tùy locale.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswpunct(L',')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswpunct(L'!')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswpunct(L'c')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswpunct(L'0')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswpunct(L' ')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswpunct(L'\n')? L"yes": L"no"); // no
}ispunct(), iswspace(), iswalnum()
iswspace()Kiểm tra wide character có là whitespace
#include <wctype.h>
int iswspace(wint_t wc);Kiểm tra c có là ký tự whitespace. Chắc là bao gồm:
' ')'\f')'\n')'\r')'\t')'\v')Các locale khác có thể đặc tả ký tự whitespace khác. iswalnum(), iswgraph(), và iswpunct() đều false với mọi ký tự whitespace.
True nếu ký tự là whitespace.
Kết quả có thể khác nhau tùy locale.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswspace(L' ')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswspace(L'\n')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswspace(L'\t')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswspace(L',')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswspace(L'!')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswspace(L'c')? L"yes": L"no"); // no
}iswupper()Kiểm tra wide character có là chữ hoa
#include <wctype.h>
int iswupper(wint_t wc);Kiểm tra một ký tự có là chữ hoa trong locale hiện tại.
Để là chữ hoa, những điều sau phải đúng:
!iscntrl(c) && !isdigit(c) && !ispunct(c) && !isspace(c)Trả về true nếu wide character là chữ hoa.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswupper(L'B')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswupper(L'c')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswupper(L'0')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswupper(L'?')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswupper(L' ')? L"yes": L"no"); // no
}isupper(), iswlower(), iswalpha(), towupper(), towlower()
iswxdigit()Kiểm tra wide character có là chữ số hex
#include <wctype.h>
int iswxdigit(wint_t wc);Trả về true nếu wide character là chữ số hex. Cụ thể là nếu nó thuộc 0-9, a-f, hoặc A-F.
True nếu ký tự là chữ số hex.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// testing this char
// v
wprintf(L"%ls\n", iswxdigit(L'B')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswxdigit(L'c')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswxdigit(L'2')? L"yes": L"no"); // yes
wprintf(L"%ls\n", iswxdigit(L'G')? L"yes": L"no"); // no
wprintf(L"%ls\n", iswxdigit(L'?')? L"yes": L"no"); // no
}iswctype()Xác định phân loại wide character
#include <wctype.h>
int iswctype(wint_t wc, wctype_t desc);Đây là con dao Thụy Sĩ của các hàm phân loại; nó gom hết mấy hàm kia vào một.
Bạn gọi nó kiểu này:
if (iswctype(c, wctype("digit"))) // or "alpha" or "space" or...và nó hành xử y như bạn đã gọi:
if (iswdigit(c))Khác biệt là bạn có thể đặc tả kiểu matching muốn làm dưới dạng chuỗi lúc runtime, nghe thì tiện.
iswctype() dựa vào giá trị trả về của lời gọi wctype() để làm việc.
Chôm từ spec, đây là các lời gọi iswctype() và các hàm tương đương:
Lời gọi iswctype() |
Tương đương hard-code |
|---|---|
iswctype(c, wctype("alnum")) |
iswalnum(c) |
iswctype(c, wctype("alpha")) |
iswalpha(c) |
iswctype(c, wctype("blank")) |
iswblank(c) |
iswctype(c, wctype("cntrl")) |
iswcntrl(c) |
iswctype(c, wctype("digit")) |
iswdigit(c) |
iswctype(c, wctype("graph")) |
iswgraph(c) |
iswctype(c, wctype("lower")) |
iswlower(c) |
iswctype(c, wctype("print")) |
iswprint(c) |
iswctype(c, wctype("punct")) |
iswpunct(c) |
iswctype(c, wctype("space")) |
iswspace(c) |
iswctype(c, wctype("upper")) |
iswupper(c) |
iswctype(c, wctype("xdigit")) |
iswxdigit(c) |
Xem tài liệu wctype() để biết hàm phụ trợ đó hoạt động ra sao.
Trả về true nếu wide character wc khớp với lớp ký tự ở desc.
Kiểm tra một phân loại ký tự nào đó khi không biết phân loại tại thời điểm compile:
#include <stdio.h> // for fflush(stdout)
#include <wchar.h>
#include <wctype.h>
int main(void)
{
wchar_t c; // Holds a single wide character (to test)
char desc[128]; // Holds the character class
// Get the character and classification from the user
wprintf(L"Enter a character and character class: ");
fflush(stdout);
wscanf(L"%lc %s", &c, desc);
// Compute the type from the given class
wctype_t t = wctype(desc);
if (t == 0)
// If the type is 0, it's an unknown class
wprintf(L"Unknown character class: \"%s\"\n", desc);
else {
// Otherwise, let's test the character and see if its that
// classification
if (iswctype(c, t))
wprintf(L"Yes! '%lc' is %s!\n", c, desc);
else
wprintf(L"Nope! '%lc' is not %s.\n", c, desc);
}
}Output:
Enter a character and character class: 5 digit
Yes! '5' is digit!
Enter a character and character class: b digit
Nope! 'b' is not digit.
Enter a character and character class: x alnum
Yes! 'x' is alnum!wctype()Hàm phụ trợ cho iswctype()
#include <wctype.h>
wctype_t wctype(const char *property);Hàm này trả về một giá trị opaque cho property cho trước, dùng để truyền làm tham số thứ hai cho iswctype().
Giá trị trả về có kiểu wctype_t.
Các property hợp lệ trong mọi locale là:
"alnum" "alpha" "blank" "cntrl"
"digit" "graph" "lower" "print"
"punct" "space" "upper" "xdigit"Các property khác có thể được định nghĩa tùy category LC_CTYPE của locale hiện tại.
Xem trang tham khảo iswctype() để biết chi tiết sử dụng.
Trả về giá trị wctype_t tương ứng với property cho trước.
Nếu truyền giá trị không hợp lệ cho property, trả về 0.
Kiểm tra một phân loại ký tự nào đó khi không biết phân loại tại thời điểm compile:
#include <stdio.h> // for fflush(stdout)
#include <wchar.h>
#include <wctype.h>
int main(void)
{
wchar_t c; // Holds a single wide character (to test)
char desc[128]; // Holds the character class
// Get the character and classification from the user
wprintf(L"Enter a character and character class: ");
fflush(stdout);
wscanf(L"%lc %s", &c, desc);
// Compute the type from the given class
wctype_t t = wctype(desc);
if (t == 0)
// If the type is 0, it's an unknown class
wprintf(L"Unknown character class: \"%s\"\n", desc);
else {
// Otherwise, let's test the character and see if its that
// classification
if (iswctype(c, t))
wprintf(L"Yes! '%lc' is %s!\n", c, desc);
else
wprintf(L"Nope! '%lc' is not %s.\n", c, desc);
}
}Output:
Enter a character and character class: 5 digit
Yes! '5' is digit!
Enter a character and character class: b digit
Nope! 'b' is not digit.
Enter a character and character class: x alnum
Yes! 'x' is alnum!towlower()Chuyển wide character hoa sang chữ thường
#include <wctype.h>
wint_t towlower(wint_t wc);Nếu ký tự là chữ hoa (tức iswupper(c) true), hàm này trả về chữ thường tương ứng.
Các locale khác nhau có thể có chữ hoa và chữ thường khác nhau.
Nếu chữ cái wc là chữ hoa, phiên bản chữ thường của chữ đó sẽ được trả về theo locale hiện tại.
Nếu chữ cái không phải chữ hoa, wc được trả về nguyên không đổi.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// changing this char
// v
wprintf(L"%lc\n", towlower(L'B')); // b (made lowercase!)
wprintf(L"%lc\n", towlower(L'e')); // e (unchanged)
wprintf(L"%lc\n", towlower(L'!')); // ! (unchanged)
}tolower(), towupper(), iswlower(), iswupper()
towupper()Chuyển wide character thường sang chữ hoa
#include <wctype.h>
wint_t towupper(wint_t wc);Nếu ký tự là chữ thường (tức iswlower(c) true), hàm này trả về chữ hoa tương ứng.
Các locale khác nhau có thể có chữ hoa và chữ thường khác nhau.
Nếu chữ cái wc là chữ thường, phiên bản chữ hoa của chữ đó sẽ được trả về theo locale hiện tại.
Nếu chữ cái không phải chữ thường, wc được trả về nguyên không đổi.
#include <wchar.h>
#include <wctype.h>
int main(void)
{
// changing this char
// v
wprintf(L"%lc\n", towupper(L'B')); // B (unchanged)
wprintf(L"%lc\n", towupper(L'e')); // E (made uppercase!)
wprintf(L"%lc\n", towupper(L'!')); // ! (unchanged)
}toupper(), towlower(), iswlower(), iswupper()
towctrans()Chuyển wide character sang chữ hoa hoặc chữ thường
#include <wctype.h>
wint_t towctrans(wint_t wc, wctrans_t desc);Đây là con dao Thụy Sĩ của các hàm chuyển đổi ký tự; nó gom hết mấy hàm kia vào một. Và “mấy hàm kia” ở đây nghĩa là towupper() và towlower(), vì đó là tất cả những gì có.
Bạn gọi nó kiểu này:
if (towctrans(c, wctrans("toupper"))) // or "tolower"và nó hành xử y như bạn đã gọi:
towupper(c);Khác biệt là bạn có thể đặc tả kiểu chuyển đổi muốn làm dưới dạng chuỗi lúc runtime, nghe thì tiện.
towctrans() dựa vào giá trị trả về của lời gọi wctrans() để làm việc.
Lời gọi towctrans() |
Tương đương hard-code |
|---|---|
towctrans(c, wctrans("toupper")) |
towupper(c) |
towctrans(c, wctrans("tolower")) |
towlower(c) |
Xem tài liệu wctrans() để biết hàm phụ trợ đó hoạt động ra sao.
Trả về ký tự wc như thể đã chạy qua towupper() hoặc towlower(), tùy giá trị của desc.
Nếu ký tự đã khớp sẵn với phân loại, nó được trả về nguyên xi.
#include <stdio.h> // for fflush(stdout)
#include <wchar.h>
#include <wctype.h>
int main(void)
{
wchar_t c; // Holds a single wide character (to test)
char desc[128]; // Holds the conversion type
// Get the character and conversion type from the user
wprintf(L"Enter a character and conversion type: ");
fflush(stdout);
wscanf(L"%lc %s", &c, desc);
// Compute the type from the given conversion type
wctrans_t t = wctrans(desc);
if (t == 0)
// If the type is 0, it's an unknown conversion type
wprintf(L"Unknown conversion: \"%s\"\n", desc);
else {
// Otherwise, let's do the conversion
wint_t result = towctrans(c, t);
wprintf(L"'%lc' -> %s -> '%lc'\n", c, desc, result);
}
}Output trên máy tôi:
Enter a character and conversion type: b toupper
'b' -> toupper -> 'B'
Enter a character and conversion type: B toupper
'B' -> toupper -> 'B'
Enter a character and conversion type: B tolower
'B' -> tolower -> 'b'
Enter a character and conversion type: ! toupper
'!' -> toupper -> '!'wctrans(), towupper(), towlower()
wctrans()Hàm phụ trợ cho towctrans()
#include <wctype.h>
wctrans_t wctrans(const char *property);Đây là hàm phụ trợ để sinh tham số thứ hai cho towctrans().
Bạn có thể truyền vào một trong hai thứ cho property:
toupper để towctrans() hành xử như towupper()tolower để towctrans() hành xử như towlower()Nếu thành công, trả về giá trị có thể dùng làm tham số desc cho towctrans().
Ngược lại, nếu property không nhận ra, trả về 0.
#include <stdio.h> // for fflush(stdout)
#include <wchar.h>
#include <wctype.h>
int main(void)
{
wchar_t c; // Holds a single wide character (to test)
char desc[128]; // Holds the conversion type
// Get the character and conversion type from the user
wprintf(L"Enter a character and conversion type: ");
fflush(stdout);
wscanf(L"%lc %s", &c, desc);
// Compute the type from the given conversion type
wctrans_t t = wctrans(desc);
if (t == 0)
// If the type is 0, it's an unknown conversion type
wprintf(L"Unknown conversion: \"%s\"\n", desc);
else {
// Otherwise, let's do the conversion
wint_t result = towctrans(c, t);
wprintf(L"'%lc' -> %s -> '%lc'\n", c, desc, result);
}
}Output trên máy tôi:
Enter a character and conversion type: b toupper
'b' -> toupper -> 'B'
Enter a character and conversion type: B toupper
'B' -> toupper -> 'B'
Enter a character and conversion type: B tolower
'B' -> tolower -> 'b'
Enter a character and conversion type: ! toupper
'!' -> toupper -> '!'https://beej.us/guide/bgc/↩︎
https://en.wikipedia.org/wiki/ANSI_C↩︎
https://en.wikipedia.org/wiki/POSIX↩︎
https://visualstudio.microsoft.com/vs/community/↩︎
https://docs.microsoft.com/en-us/windows/wsl/install-win10↩︎
https://developer.apple.com/xcode/↩︎
https://beej.us/guide/bgclr/↩︎
https://en.cppreference.com/↩︎
https://groups.google.com/g/comp.lang.c↩︎
https://www.reddit.com/r/C_Programming/↩︎
Việc này không thay đổi kiểu của x ở ngữ cảnh khác, nó chỉ có hiệu lực trong lần dùng cụ thể này trong biểu thức này.↩︎
Lưu ý ngầm định này chỉ áp dụng cho main(), không áp dụng cho bất cứ hàm nào khác.↩︎
https://en.wikipedia.org/wiki/Complex_conjugate↩︎
https://en.wikipedia.org/wiki/Riemann_sphere↩︎
Thật ra nó chỉ cần là modifiable lvalue, nên không nhất thiết là biến. Nhưng bạn cứ xem nó như biến cũng được.↩︎
https://man.archlinux.org/man/errno.3.en↩︎
https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-160↩︎
https://en.wikipedia.org/wiki/Subnormal_number↩︎
Giá trị nhỏ nhất của unsigned char là 0. Với unsigned short và unsigned long cũng vậy. Hay bất kỳ kiểu unsigned nào, cũng thế.↩︎
https://en.wikipedia.org/wiki/Two%27s_complement↩︎
Nhớ là char chỉ là integer cỡ một byte.↩︎
Dù hệ thống định nghĩa MATH_ERRNO là 1 và MATH_ERREXCEPT là 2, tốt nhất luôn dùng tên ký hiệu. Phòng hờ.↩︎
https://en.wikipedia.org/wiki/Denormal_number↩︎
Đây là trên máy tôi. Một số hệ thống sẽ có ngưỡng mà số trở thành subnormal khác, hoặc có thể không hỗ trợ giá trị subnormal.↩︎
https://en.wikipedia.org/wiki/E_(mathematical_constant)↩︎
https://en.wikipedia.org/wiki/Denormal_number↩︎
https://en.wikipedia.org/wiki/Pythagorean_theorem↩︎
https://en.wikipedia.org/wiki/Error_function↩︎
https://en.wikipedia.org/wiki/Error_function↩︎
https://en.wikipedia.org/wiki/Gamma_function↩︎
https://en.wikipedia.org/wiki/Gamma_function↩︎
https://en.cppreference.com/w/c/numeric/math/remquo↩︎
https://en.cppreference.com/w/c/numeric/math/remquo↩︎
Một quiet NaN là NaN không raise bất kỳ exception nào.↩︎
https://man.archlinux.org/man/sigaction.2.en↩︎
Như kiểu được gửi từ lệnh kill trên Unix.]↩︎
https://en.wikipedia.org/wiki/Data_structure_alignment↩︎
Có thể nó phụ thuộc vào môi trường run-time và không thể biết ở compile-time.↩︎
https://en.cppreference.com/w/cpp/atomic/ATOMIC_VAR_INIT↩︎
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1138r0.pdf↩︎
Hiệu quả thì cái này làm cùng việc, nhưng rõ ràng nó không nguyên tử.↩︎
Spec nói: “Cái thất bại tự phát này cho phép cài đặt compare-and-exchange trên một lớp máy rộng hơn, ví dụ như các máy load-locked store-conditional.” Và thêm: “Khi compare-and-exchange nằm trong vòng lặp, phiên bản weak sẽ cho hiệu năng tốt hơn trên một số nền tảng. Khi một compare-and-exchange weak sẽ cần vòng lặp còn strong thì không, thì strong được ưu tiên hơn.”↩︎
Đừng dùng cái này trừ khi bạn biết mình đang làm gì—dùng chức năng mutex của thread thay vào đó. Nó sẽ cho phép thread bị chặn ngủ và ngừng gặm CPU.↩︎
Đừng dùng cái này trừ khi bạn biết mình đang làm gì—dùng chức năng mutex của thread thay vào đó. Nó sẽ cho phép thread bị chặn ngủ và ngừng gặm CPU.↩︎
https://en.wikipedia.org/wiki/Data_structure_alignment↩︎
https://man.archlinux.org/man/unlinkat.2.en#DESCRIPTION↩︎
https://man.archlinux.org/man/mkstemp.3.en↩︎
https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/↩︎
https://stackoverflow.com/questions/17017331/c99-vscanf-for-dummies/17018046#17018046↩︎
http://man.cat-v.org/unix-1st/3/atof↩︎
http://man.cat-v.org/unix-1st/3/atoi↩︎
https://en.wikipedia.org/wiki/Radix↩︎
https://stackoverflow.com/questions/10984974/why-do-people-say-there-is-modulo-bias-when-using-a-random-number-generator↩︎
https://mumble.net/~campbell/2014/04/28/uniform-random-float↩︎
https://www.gnu.org/software/gsl/doc/html/rng.html↩︎
Fan của Minecraft có thể nhớ rằng khi tạo thế giới mới, họ được cho tuỳ chọn nhập vào một seed số ngẫu nhiên. Giá trị duy nhất đó được dùng để sinh ra toàn bộ thế giới ngẫu nhiên đó. Và nếu bạn của bạn bắt đầu thế giới với cùng seed bạn dùng, họ sẽ nhận được cùng thế giới bạn có.↩︎
https://en.wikipedia.org/wiki/Unix_time↩︎
Spec của C không quy định chính xác time(NULL) sẽ trả về gì, nhưng spec POSIX thì có! Và gần như ai cũng trả về đúng thứ đó: số giây kể từ epoch.↩︎
https://en.wikipedia.org/wiki/Data_structure_alignment↩︎
“Thử tưởng tượng mọi sự sống như bạn biết dừng ngay lập tức và mọi phân tử trong cơ thể bạn nổ tung ở tốc độ ánh sáng.” —Egon Spengler↩︎
https://en.wikipedia.org/wiki/Core_dump↩︎
quick_exit() khác exit() ở chỗ file đang mở có thể không được flush và file tạm có thể không bị xoá.↩︎
“Tại chỗ” (in-place) nghĩa là mảng gốc sẽ chứa kết quả; không có mảng mới nào được cấp phát.↩︎
Nó luôn trả về số byte mà chuỗi đã transform chiếm, nhưng trong trường hợp này vì s1 là NULL, nó không thực sự ghi ra một chuỗi đã transform.↩︎
Đúng ra nên như vậy vì có spurious wakeup.↩︎
Ừm, ít nhất là chừng nào bạn có đủ core rảnh. OS sẽ lên lịch cho chúng tuỳ khả năng.↩︎
Ví dụ, nếu một destructor làm cho nhiều biến khác được đặt lại.↩︎
Các hệ kiểu Unix có syscall sleep() ngủ theo số giây nguyên. Nhưng thrd_sleep() có lẽ portable hơn và thêm nữa còn cho độ phân giải dưới-giây!↩︎
Khi bạn nói GMT, trừ khi bạn đang nói cụ thể về múi giờ chứ không phải về thời điểm, có lẽ thứ bạn muốn nói là “UTC”.↩︎
Spec thực ra không nói “clock tick”, nhưng tôi… thì nói.↩︎
Trừ khi bạn đang ở trên một hệ thống POSIX nơi time_t chắc chắn là số nguyên, lúc đó bạn có thể trừ. Nhưng bạn vẫn nên dùng difftime() để portable (khả chuyển) tối đa.↩︎
https://man.archlinux.org/man/timegm.3.en↩︎
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mkgmtime-mkgmtime32-mkgmtime64?view=msvc-160↩︎
https://man.archlinux.org/man/timegm.3.en↩︎
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mkgmtime-mkgmtime32-mkgmtime64?view=msvc-160↩︎
https://en.wikipedia.org/wiki/Unix_time↩︎
https://en.wikipedia.org/wiki/ISO_week_date↩︎
https://en.wikipedia.org/wiki/Symbols_for_Legacy_Computing↩︎
https://stackoverflow.com/questions/17017331/c99-vscanf-for-dummies/17018046#17018046↩︎
Đây là một biến, không phải macro, nên nếu bạn dùng nó để định nghĩa mảng, đó sẽ là mảng có độ dài biến thiên (variable-length array).↩︎