Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

sjrct
Copy link
Contributor

@sjrct sjrct commented Jul 10, 2023

This does a few things with the c/en tutorial.

  1. Fix the word wrapping. A lot of lines were longer than 80 characters. Some small copy edits here to prevent line breaks in strange places.
  2. Added note about void in to signal empty parameter lists and add void to existing empty param functions
  3. Note about not using braces for one-statement control blocks.
  4. Note about using field initializers for structs
  5. Note about #pragma once, and about static inline funcs in headers. Wasn't sure if this was too niche to be usefully included.
  6. Small copy edits

  • I solemnly swear that this is all original content of which I am the original author
  • Pull request title is prepended with [language/lang-code] (example [python/fr-fr] or [java/en])
  • Pull request touches only one file (or a set of logically related files with similar changes made)
  • Content changes are aimed at intermediate to experienced programmers (this is a poor format for explaining fundamental programming concepts)
  • If you've changed any part of the YAML Frontmatter, make sure it is formatted according to CONTRIBUTING.md
    • Yes, I have double-checked quotes and field names!

c.html.markdown Outdated Show resolved Hide resolved
c.html.markdown Outdated Show resolved Hide resolved
// 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.)
Copy link
Collaborator

@verhovsky verhovsky May 21, 2024

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

Suggested change
// 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.)

Copy link
Contributor Author

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.

c.html.markdown Outdated Show resolved Hide resolved
c.html.markdown Outdated Show resolved Hide resolved
Comment on lines +73 to +74
void function_1(void);
int function_2(int a, float b);
Copy link
Collaborator

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.

Suggested change
void function_1(void);
int function_2(int a, float b);
void function_1();
int function_2(void);

Copy link
Contributor Author

@sjrct sjrct May 22, 2024

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

c.html.markdown Outdated Show resolved Hide resolved
Comment on lines +688 to 689
void testFunc(void) {
extern int i; //i here is now using external variable i
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void testFunc2(void) {
void testFunc2() {

c.html.markdown Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants