-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.c
118 lines (102 loc) · 1.99 KB
/
examples.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* SPDX-License-Identifier: MPL-2.0 */
/*
* Example usage for dbg.h
* Copyright (C) 2023 James Morris
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <complex.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wchar.h>
#include "dbg.h"
#define eputs(s) (fputs((s), stderr) != EOF ? fputc('\n', stderr) : EOF)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int main(void) {
eputs("Booleans:");
bool b = true;
dbg(b);
dbg(false);
eputs("");
eputs("Characters:");
char c = 'c';
dbg(c);
wchar_t wc = L'd';
dbgfmt(wc, L'%lc');
wc = dbgfmt(wc + 1, L'%c');
dbgfmt(wc, L'%lc');
eputs("");
eputs("Signed ints:");
signed char sc = 1;
dbg(sc);
short s = 2;
dbg(s);
int i = 3;
dbg(i);
long l = 4;
dbg(l);
long long ll = 5;
dbg(ll);
eputs("");
eputs("Unsigned ints:");
unsigned char uc = 6;
dbg(uc);
unsigned short us = 7;
dbg(us);
unsigned int ui = 8;
dbg(ui);
unsigned long ul = 9;
dbg(ul);
unsigned long long ull = 10;
dbg(ull);
eputs("");
eputs("Floats and doubles:");
float f = 11.0f;
dbg(f);
double d = 12.0;
dbg(d);
long double ld = 13.0;
dbg(ld);
eputs("");
eputs("Strings and pointers:");
char* cp = "14";
dbg(cp);
wchar_t* wp = L"15";
dbg(wp);
void* vp = cp;
dbg(vp);
dbg(NULL);
eputs("");
char const* ccp = "16";
dbg(ccp);
wchar_t const* cwp = L"17";
dbg(cwp);
void const* cvp = ccp;
dbg(cvp);
eputs("");
struct { int x; int y; } point = {100, 200};
eputs("Struct members");
dbg(point.x);
dbg(point.y);
eputs("");
eputs("Arbitrary expressions:");
void* vp2 = dbg(malloc(sizeof(char[10])));
dbg(vp2);
free(vp2);
eputs("");
dbg(i = 2 + 4);
dbg(i);
eputs("");
eputs("Complex numbers:");
dbg(I);
float complex fc = CMPLXF(1.0, -1.0);
dbg(fc);
double complex dc = CMPLX(2.0, -2.0);
dbg(dc);
long double complex ldc = CMPLXL(3.0, -3.0);
dbg(ldc);
eputs("");
return 0;
}