-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[c/en] Wrapping fixes and some copy edits/small additions #4704
base: master
Are you sure you want to change the base?
Conversation
Semicolon inside empty braces is not required
// It's good practice to use `const char *' when referring to a string literal, | ||
// since string literals shall not be modified (i.e. "foo"[0] = 'a' is ILLEGAL.) | ||
// It's good practice to use `const char *' when referring to a string literal | ||
// since string literals shall not be modified (i.e. foo[0] = 'a' is ILLEGAL.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pseudo code is clearer
// since string literals shall not be modified (i.e. foo[0] = 'a' is ILLEGAL.) | |
// since string literals shall not be modified (i.e. "foo"[0] = 'a' is ILLEGAL.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change makes sense but I also think that indexing a string literal will probably make readers take a double take, and I wonder if we could just drop the parenthetical entirely.
void function_1(void); | ||
int function_2(int a, float b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine the way it is and is easier to understand when it's simpler like this. I understand ()
is a compiler warning but in practice it doesn't matter if you don't even know how to access the variable length arguments of functions in C. I think mentioning (void)
at the end is good but keeping it simple at the beginning is better.
void function_1(void); | |
int function_2(int a, float b); | |
void function_1(); | |
int function_2(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with -Wall -Wextra
gcc (at least version 13.2.0 for me) compiles calling functions with ()
for the parameter list with some arbitrary parameters without any warning. clang does give me some warning. C23 did change this behavior though, making (void)
and ()
equivalent parameter lists for function declarations, and I know gcc is on v14 now, so my OS's version is probably a bit out of date and this will not become as relevant for new C in not too long.
Having been burning by that unexpected behavior in the past, it was my intuition to include it when making these changes originally, but with C23, putting it off to the end makes sense, or even leaving it out. I'll make some changes shortly
void testFunc(void) { | ||
extern int i; //i here is now using external variable i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void testFunc(void) { | |
extern int i; //i here is now using external variable i | |
void testFunc() { | |
extern int i; // i here is now using external variable i |
extern int i; //i here is now using external variable i | ||
} | ||
|
||
// make external variables private to source file with static: | ||
static int j = 0; //other files using testFunc2() cannot access variable j | ||
void testFunc2() { | ||
void testFunc2(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void testFunc2(void) { | |
void testFunc2() { |
Co-authored-by: Boris Verkhovskiy <[email protected]>
Co-authored-by: Boris Verkhovskiy <[email protected]>
Co-authored-by: Boris Verkhovskiy <[email protected]>
Co-authored-by: Boris Verkhovskiy <[email protected]>
Co-authored-by: Boris Verkhovskiy <[email protected]>
Co-authored-by: Boris Verkhovskiy <[email protected]>
This does a few things with the c/en tutorial.
void
in to signal empty parameter lists and addvoid
to existing empty param functions#pragma once
, and aboutstatic inline
funcs in headers. Wasn't sure if this was too niche to be usefully included.[language/lang-code]
(example[python/fr-fr]
or[java/en]
)