-
Notifications
You must be signed in to change notification settings - Fork 101
Add LLVM libc sample #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LLVM libc sample #538
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,13 @@ | |
| #include <string.h> | ||
| #include <math.h> | ||
|
|
||
| /* Example that uses heap, string and math library */ | ||
| // Implementation of errno | ||
| int *__llvm_libc_errno() { | ||
| static int errno; | ||
| return &errno; | ||
| } | ||
|
|
||
| // Example that uses heap, string and math library. | ||
|
|
||
| int main(void) { | ||
| const char *hello_s = "hello "; | ||
|
|
@@ -32,7 +38,9 @@ int main(void) { | |
| strncpy(out_s, hello_s, hello_s_len + 1); | ||
| assert(out_s_len >= strlen(out_s) + world_s_len + 1); | ||
| strncat(out_s, world_s, world_s_len + 1); | ||
| printf("%s %d\n", out_s, abs(-3)); | ||
| // 2024-10-17 Embedded printf implementation does not currently | ||
| // support printing floating point numbers. | ||
| printf("%s %li\n", out_s, lround(400000 * atanf(1.0f))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because you wrote I think that's actually a good thing – it makes it a better test! I point it out because you probably didn't do it on purpose, but I quite like it, and perhaps it's better not to "fix" it :-) |
||
| free(out_s); | ||
| return 0; | ||
| } | ||
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.
Sorry to do another pedantic one, but I recommend calling that internal variable something other than
errno. If a user starts from this code and adds#include <errno.h>, then the nameerrnowill surely become a macro, making this function into nonsense. Any other name is fine.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.
Thanks for spotting. I've used a name that doesn't contain errno.