Created
August 18, 2013 05:58
-
-
Save phardy/6260128 to your computer and use it in GitHub Desktop.
Pebble strtol test #1. This shows strtol returning 0 when compiled with SDK 1.12.
When numstr is set to "-37" it causes a runtime crash.
This file contains hidden or 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
| #include "pebble_os.h" | |
| #include "pebble_app.h" | |
| #include "pebble_fonts.h" | |
| #define MY_UUID { 0x92, 0x40, 0x44, 0xC0, 0xCA, 0x8A, 0x43, 0x64, 0x9D, 0xDE, 0x11, 0x33, 0x6F, 0x04, 0xA9, 0x3F } | |
| PBL_APP_INFO(MY_UUID, | |
| "strtol test", "Your Company", | |
| 1, 0, /* App version */ | |
| DEFAULT_MENU_ICON, | |
| APP_INFO_STANDARD_APP); | |
| Window window; | |
| TextLayer textlayer; | |
| char outstr[20]; | |
| void handle_init(AppContextRef ctx) { | |
| window_init(&window, "Window Name"); | |
| window_stack_push(&window, true /* Animated */); | |
| text_layer_init(&textlayer, GRect(10, 10, 100, 100)); | |
| layer_add_child(&window.layer, &textlayer.layer); | |
| text_layer_set_text(&textlayer, "calling strtol"); | |
| char numstr[] = "37"; | |
| long mynum = strtol(numstr, NULL, 10); | |
| snprintf(outstr, 19, "strtol returned: %ld", mynum); | |
| text_layer_set_text(&textlayer, outstr); | |
| } | |
| void pbl_main(void *params) { | |
| PebbleAppHandlers handlers = { | |
| .init_handler = &handle_init | |
| }; | |
| app_event_loop(params, &handlers); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment