Skip to content

Commit f48340d

Browse files
committed
Add libraries to slogan
1 parent 0c1d8b9 commit f48340d

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/cirosantilli/cpp-cheat.svg?branch=master)](https://travis-ci.org/cirosantilli/cpp-cheat)
44

5-
C and C++ minimal examples. Asserts used wherever possible. Cheatsheets, tutorials and mini-projects.
5+
C and C++ minimal examples. Asserts used wherever possible. Hello worlds for cool third party libraries. Cheatsheets, tutorials and mini-projects.
66

77
[Assembly Cheat](https://github.com/cirosantilli/assembly-cheat) contains lower level issues, like assembly, ELF and Binutils.
88

‎c/ctype_h.c‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
/*
22
# ctype.h
33
4-
Character classficiation and conversion functions.
4+
Character classification and conversion functions.
5+
6+
# unsigned char typecast
7+
8+
I think it is required to avoid undefined behaviour, because
9+
char may or not be signed
10+
http://stackoverflow.com/questions/2054939/is-char-signed-or-unsigned-by-default
11+
and ctype functions UB if input is neither fits into `unsigned char` nor is EOF.
12+
13+
Mentioned at: http://www.greenend.org.uk/rjk/tech/cfu.html
14+
15+
Conversions to unsigned types are always defined (modulo),
16+
and char -> unsigned char is a bijection.
517
*/
618

719
#include "common.h"
820

9-
int main() {
21+
int main(void) {
1022
/* # isspace */
1123
{
12-
assert(isspace(' '));
13-
assert(isspace('\n'));
14-
assert(!isspace('a'));
24+
assert(isspace((unsigned char)' '));
25+
assert(isspace((unsigned char)'\n'));
26+
assert(!isspace((unsigned char)'a'));
1527
}
1628

1729
/* # isdigit */
1830
{
19-
assert(isdigit('0'));
20-
assert(!isdigit('a'));
31+
assert(isdigit((unsigned char)'0'));
32+
assert(!isdigit((unsigned char)'a'));
2133
}
2234

2335
/* # ispunct */
2436
{
25-
assert(ispunct('"'));
26-
assert(ispunct('('));
27-
assert(ispunct('.'));
28-
assert(!ispunct('a'));
29-
assert(!ispunct('0'));
37+
assert(ispunct((unsigned char)'"'));
38+
assert(ispunct((unsigned char)'('));
39+
assert(ispunct((unsigned char)'.'));
40+
assert(!ispunct((unsigned char)'a'));
41+
assert(!ispunct((unsigned char)'0'));
3042
}
3143

3244
/*
@@ -40,8 +52,8 @@ int main() {
4052
http://stackoverflow.com/questions/2661766/c-convert-a-mixed-case-string-to-all-lower-case
4153
*/
4254
{
43-
assert(tolower('A') == 'a');
44-
assert(toupper('a') == 'A');
55+
assert(tolower((unsigned char)'A') == 'a');
56+
assert(toupper((unsigned char)'a') == 'A');
4557
}
4658

4759
return EXIT_SUCCESS;

‎c/errno_h.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
Each error has an error message string associated to it.
1919
To get that error message, consider using `strerror`.
2020
To print an error message to stderr, consider using `perror`.
21+
22+
Success of calls does not normally set errno,
23+
and you can and should set it yourself in most cases:
24+
http://stackoverflow.com/questions/9856822/should-i-set-errno
2125
*/
2226

2327
#include "common.h"

‎c/interactive/audio_gen.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TODO
88
Currently, hitting the same not twice sounds the same as hitting it once for double the time,
99
(except for the tic of phase, which is a bug as well...)
1010
- drum / percurssion synth
11+
- siren sound TODO Mechanical: https://www.youtube.com/watch?v=uckkpr2b8U8
1112
*/
1213

1314
#include <math.h>

‎c/operator.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,12 @@ int main() {
627627
Called ternary operator since it is the only operator that
628628
takes 3 inputs.
629629
630-
It seems that the only use for the ternary operator is writing less,
631-
so it is completely redundant with and if else:
632-
http://stackoverflow.com/questions/758849/the-ternary-conditional-operator-in-c
630+
Likely exists because of CMOV instructions. But with branch preditction CMOV can be slower than if / else:
631+
http://stackoverflow.com/questions/6754454/speed-difference-between-if-else-and-ternary-operator-in-c?lq=1#comment8007791_6754495
632+
633+
- http://stackoverflow.com/questions/758849/the-ternary-conditional-operator-in-c
634+
- http://stackoverflow.com/questions/3565368/ternary-operator-vs-if-else
635+
- http://stackoverflow.com/questions/6754454/speed-difference-between-if-else-and-ternary-operator-in-c?lq=1
633636
*/
634637
{
635638
assert((1 < 2 ? 3 : 4) == 3);

0 commit comments

Comments
 (0)