{"action":"created","issue":{"url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/174","labels_url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/174/labels{/name}","comments_url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/174/comments","events_url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/174/events","html_url":"https://github.com/Traumflug/Teacup_Firmware/issues/174","id":95762562,"number":174,"title":"Variable number of arguments and 16 vs. 32 bits","user":{"login":"Traumflug","id":318581,"avatar_url":"https://avatars.githubusercontent.com/u/318581?v=3","gravatar_id":"","url":"https://api.github.com/users/Traumflug","html_url":"https://github.com/Traumflug","followers_url":"https://api.github.com/users/Traumflug/followers","following_url":"https://api.github.com/users/Traumflug/following{/other_user}","gists_url":"https://api.github.com/users/Traumflug/gists{/gist_id}","starred_url":"https://api.github.com/users/Traumflug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Traumflug/subscriptions","organizations_url":"https://api.github.com/users/Traumflug/orgs","repos_url":"https://api.github.com/users/Traumflug/repos","events_url":"https://api.github.com/users/Traumflug/events{/privacy}","received_events_url":"https://api.github.com/users/Traumflug/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-17T23:17:16Z","updated_at":"2015-07-18T00:05:37Z","closed_at":null,"body":"In sersendf.c we have this code:\r\n\r\n```C\r\n#include\t<stdarg.h>\r\n\r\n#ifdef SIMULATOR\r\n  #define GET_ARG(T) (va_arg(args, int))\r\n#else\r\n  #define GET_ARG(T) (va_arg(args, T))\r\n#endif\r\n[...]\r\n    if (j == 4)\r\n        serwrite_uint32(GET_ARG(uint32_t));\r\n    else\r\n        serwrite_uint16(GET_ARG(uint16_t));\r\n```\r\nOn 32-bit ARM, this throws the following warning:\r\n\r\n```\r\nsersendf.c:122:52: warning: 'uint16_t' is promoted to 'int' when passed through '...'\r\n             serwrite_uint16(GET_ARG(uint16_t));\r\n                                                    ^\r\nsersendf.c:122:52: note: (so you should pass 'int' not 'uint16_t' to 'va_arg')\r\nsersendf.c:122:52: note: if this code is reached, the program will abort\r\n```\r\n\r\nva_arg man page comes with an example, which talks about \"promoted types\". Whatever that means:\r\n```C\r\n              case 'c':              /* char */\r\n                   /* need a cast here since va_arg only\r\n                      takes fully promoted types */\r\n                   c = (char) va_arg(ap, int);\r\n```\r\nNow I'm obviously searching for a proper solution. Ideally one without #ifdef __ ARMEL__, #ifdef __ AVR__ and such kludges. Googling didn't bring up much. Also nothing about finding out what a \"fully promoted type\" is. Is it safe to always use an int, together with a cast? Like\r\n\r\n```C\r\n    serwrite_uint16((uint16_t)va_arg(args, int));\r\n    serwrite_uint32((uint32_t)va_arg(args, int));\r\n```\r\nOn 16-bit, int is 2 bytes, while fetching an uint32_t should pull 4 bytes from the argument list.\r\n\r\nOr is there some way to test for the size of the promoted type? Like:\r\n\r\n```C\r\n#define GET_ARG(T) ((sizeof(int) < sizeof(T)) ? (T)va_arg(args, int) : (T)va_arg(args, T))\r\n```\r\n(probably won't compile warning-free, but I hope you get the idea.)\r\n\r\nThanks for the insights :-)"},"comment":{"url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/comments/122458532","html_url":"https://github.com/Traumflug/Teacup_Firmware/issues/174#issuecomment-122458532","issue_url":"https://api.github.com/repos/Traumflug/Teacup_Firmware/issues/174","id":122458532,"user":{"login":"triffid","id":164122,"avatar_url":"https://avatars.githubusercontent.com/u/164122?v=3","gravatar_id":"","url":"https://api.github.com/users/triffid","html_url":"https://github.com/triffid","followers_url":"https://api.github.com/users/triffid/followers","following_url":"https://api.github.com/users/triffid/following{/other_user}","gists_url":"https://api.github.com/users/triffid/gists{/gist_id}","starred_url":"https://api.github.com/users/triffid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/triffid/subscriptions","organizations_url":"https://api.github.com/users/triffid/orgs","repos_url":"https://api.github.com/users/triffid/repos","events_url":"https://api.github.com/users/triffid/events{/privacy}","received_events_url":"https://api.github.com/users/triffid/received_events","type":"User","site_admin":false},"created_at":"2015-07-18T00:05:37Z","updated_at":"2015-07-18T00:05:37Z","body":"I'd use a typedef in the platform-specific header, where we expect to see\nifdefs\n"}}