libcs50 icon indicating copy to clipboard operation
libcs50 copied to clipboard

Define internal vget_string helper function

Open rillig opened this issue 5 years ago • 1 comments

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 calls vfprintf internally.
  • there's vfprintf, which takes a va_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.

rillig avatar Aug 16 '19 20:08 rillig

When trying out libcs50 in JetBrains CLion, the definition of the get_string macro produces this completion:

image

This is unnecessarily confusing and should be fixed by not needing the macro at all.

rillig avatar Aug 19 '19 16:08 rillig