libcs50
libcs50 copied to clipboard
Define internal vget_string helper function
Instead of messing around with the get_string
macro, and having one definition inside cs50.c and another definition everywhere else, the cs50 code should demonstrate good knowledge of the C programming language and its larger ecosystem by implementing get_string
in the same way as the C Standard Library implements fprintf
:
- there's
fprintf
, which takes varargs and behaves as if it callsvfprintf
internally. - there's
vfprintf
, which takes ava_list
as argument.
This makes the code much cleaner and gets rid of the confusing macro. Remember, your students will look at that code and will use it as a role model, and if they later learn that your code style is bad, they will mistrust you in everything else you taught them, and rightly so.
When trying out libcs50 in JetBrains CLion, the definition of the get_string
macro produces this completion:
This is unnecessarily confusing and should be fixed by not needing the macro at all.