cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.74k stars 853 forks source link

are these lines still needed? #151

Closed dmalan closed 5 years ago

dmalan commented 5 years ago
  1. https://github.com/cs50/libcs50/blob/2019/src/cs50.c#L56
  2. https://github.com/cs50/libcs50/blob/2019/src/cs50.c#L57
  3. https://github.com/cs50/libcs50/blob/2019/src/cs50.c#L77
  4. https://github.com/cs50/libcs50/blob/2019/src/cs50.c#L461
  5. https://github.com/cs50/libcs50/blob/2019/src/cs50.h#L101

CC @kzidane

cmlsharp commented 5 years ago

Yes on all counts. Each of those lines is necessary to allow the printf-like arguments to get_*.

dmalan commented 5 years ago

@crossroads1112 can you remind me what role https://github.com/cs50/libcs50/blob/2019/src/cs50.h#L101 plays specifically? Is that trick necessary anymore, if we require now that get_string have at least one argument (the prompt) anyway? It's really just the second, third, etc. arguments that are optional now?

cmlsharp commented 5 years ago

That trick was to allow get_string to be called internally by get_int etc. There are two contexts in which get_string can be called: directly, in which it gets its arguments variadic arguments the standard way, or internally by get_int et al in which case their variadic arguments have already been stored in a va_list. This first parameter disambiguates between these two cases. When getstring is called by students, the first parameter is NULL whereas get* pass their own va_list as its first parameter

dmalan commented 5 years ago

Ah, right, thanks!