From 8291fb2d7d376186a19e643e92aacb9ed9412395 Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 8 Dec 2014 13:27:06 +0100 Subject: Update c.html.markdown --- c.html.markdown | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index f44da38e..b5b804af 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -26,13 +26,15 @@ Multi-line comments look like this. They work in C89 as well. Multi-line comments don't nest /* Be careful */ // comment ends on this line... */ // ...not this one! - // Constants: #define +// Constants: #define #define DAYS_IN_YEAR 365 - // Enumeration constants are also ways to declare constants. - enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT}; +// Enumeration constants are also ways to declare constants. +// All statements must end with a semicolon +enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT}; // MON gets 2 automatically, TUE gets 3, etc. + // Import headers with #include #include #include @@ -57,7 +59,6 @@ int main() { // print output using printf, for "print formatted" // %d is an integer, \n is a newline printf("%d\n", 0); // => Prints 0 - // All statements must end with a semicolon /////////////////////////////////////// // Types -- cgit v1.2.3 From d1171443ddc0eda7cbabfc41d110a76a67e494ab Mon Sep 17 00:00:00 2001 From: mordner Date: Thu, 8 Jan 2015 23:21:39 +0100 Subject: Fixed one line being cut off and a comment about the export attribute was referring to the wrong function and variable. --- c.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index b5b804af..7670824a 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -386,7 +386,8 @@ int main() { // or when it's the argument of the `sizeof` or `alignof` operator: int arraythethird[10]; int *ptr = arraythethird; // equivalent with int *ptr = &arr[0]; - printf("%zu, %zu\n", sizeof arraythethird, sizeof ptr); // probably prints "40, 4" or "40, 8" + printf("%zu, %zu\n", sizeof arraythethird, sizeof ptr); + // probably prints "40, 4" or "40, 8" // Pointers are incremented and decremented based on their type @@ -477,7 +478,7 @@ void testFunc() { } //make external variables private to source file with static: -static int j = 0; //other files using testFunc() cannot access variable i +static int j = 0; //other files using testFunc2() cannot access variable j void testFunc2() { extern int j; } -- cgit v1.2.3 From 21fa7d7e391f4d03d5f527043fec73fd7260334a Mon Sep 17 00:00:00 2001 From: Devin McGinty Date: Fri, 30 Jan 2015 16:42:35 -0500 Subject: Change explanation of unsigned types --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 7670824a..1696d28f 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -85,7 +85,7 @@ int main() { // doubles are usually 64-bit floating-point numbers double x_double = 0.0; // real numbers without any suffix are doubles - // integer types may be unsigned (only positive) + // integer types may be unsigned (greater than or equal to zero) unsigned short ux_short; unsigned int ux_int; unsigned long long ux_long_long; -- cgit v1.2.3 From e267eed62caf49d6d2b0d91c60d30b700d08729f Mon Sep 17 00:00:00 2001 From: Max Filippov Date: Mon, 30 Mar 2015 10:08:30 +0300 Subject: c.html: fix #1021 (bitwise negation and shifting into the sign bit) 0x0f is of type int, for 32-bit int the result is 0xfffffff0. 31'st bit is the sign bit of a 32-bit wide int. --- c.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 1696d28f..d3f20eda 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -234,7 +234,7 @@ int main() { // same with j-- and --j // Bitwise operators! - ~0x0F; // => 0xF0 (bitwise negation, "1's complement") + ~0x0F; // => 0xFFFFFFF0 (bitwise negation, "1's complement", example result for 32-bit int) 0x0F & 0xF0; // => 0x00 (bitwise AND) 0x0F | 0xF0; // => 0xFF (bitwise OR) 0x04 ^ 0x0F; // => 0x0B (bitwise XOR) @@ -242,7 +242,7 @@ int main() { 0x02 >> 1; // => 0x01 (bitwise right shift (by 1)) // Be careful when shifting signed integers - the following are undefined: - // - shifting into the sign bit of a signed integer (int a = 1 << 32) + // - shifting into the sign bit of a signed integer (int a = 1 << 31) // - left-shifting a negative number (int a = -1 << 2) // - shifting by an offset which is >= the width of the type of the LHS: // int a = 1 << 32; // UB if int is 32 bits wide -- cgit v1.2.3