Skip to content

type string is badly defined #175

@rillig

Description

@rillig

As pointed out in #163, the typedef for string is wrong.

When I add the following code to cs50.c:

void demo(void) {
    get_string(NULL, "string literal");
}

and compile the file using this command line:

$ LC_ALL=C gcc -Wall -Wextra -O2 -I. cs50.c -c -pedantic -Wwrite-strings

I get these warnings:

cs50.c: In function 'demo':
cs50.c:456:22: warning: passing argument 2 of 'get_string' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     get_string(NULL, "string literal");
                      ^~~~~~~~~~~~~~~~
cs50.c:78:8: note: expected 'string {aka char * const}' but argument is of type 'const char *'
 string get_string(va_list *args, const string format, ...)
        ^~~~~~~~~~

If you had omitted the wrong typedef for string, this problem would not appear.
Please scratch it from all teaching material, as it is misleading.
It's your responsibility as a teacher not to teach wrong things.
You should also actively search for proof readers for the existing cs50 library, since relying on "the internet community" can take a very long time in which you (by your faulty teaching content) create lots of unnecessary work on Stack Overflow and Code Review for all those volunteers who have to correct your mistakes.

See https://codereview.stackexchange.com/a/225437 for a case where one of your students had to be corrected because of your misleading teaching.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions