-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrected printf of long and long long args. Closes #314
- Loading branch information
1 parent
b2e8893
commit 9173b9b
Showing
1 changed file
with
29 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9173b9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing pointer to
va_list
is another option (https://stackoverflow.com/questions/3369588/pass-va-list-or-pointer-to-va-list). It will encapsulate consuming of arguments9173b9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ledvinap, I had the same idea, but it turned out to be problematic. According to http://en.cppreference.com/w/cpp/utility/variadic/va_list it is not OK to use a va_list after it has been passed to another function as a pointer.
I'm not an expert on variadic functions but I realized it can be a bit more complex than I used to think. Apparently on some architectures the first arguments are passed to a function in registers, as opposed to the stack, which complicates matters when passing them on to the next function.
The behaviour in the unit tests (running on my Mac) and in the Crazyflie are also very different, some solutions did work on one platform but not the other, some did not even compile on one of the platforms but was OK on the other.
I decided that it was easier to not pass the va_list on to the next function :-)
9173b9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just for completeness)
from cppreference: It is legal to pass a pointer to a va_list object to another function and then use that object after the function returns.
And footnote from standard (from https://stackoverflow.com/questions/3369588/pass-va-list-or-pointer-to-va-list) 215) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns
Even amd64 implementation uses struct, pointer to this struct can be passed around (both saved registers and stack are in same place in called function)
9173b9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.