Title: handling of defined() conditions nested in function like macros · Issue #75 · cppcheck-opensource/simplecpp · GitHub
Open Graph Title: handling of defined() conditions nested in function like macros · Issue #75 · cppcheck-opensource/simplecpp
X Title: handling of defined() conditions nested in function like macros · Issue #75 · cppcheck-opensource/simplecpp
Description: defined() conditions in function like macros are not handled correctly. minimal example, which expects __FOO__ to be defined or not. #include
Open Graph Description: defined() conditions in function like macros are not handled correctly. minimal example, which expects __FOO__ to be defined or not. #include
X Description: defined() conditions in function like macros are not handled correctly. minimal example, which expects __FOO__ to be defined or not. #include <stdio.h> #define macro(var) (defined(__ ## var #...
Opengraph URL: https://github.com/cppcheck-opensource/simplecpp/issues/75
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"handling of defined() conditions nested in function like macros","articleBody":"`defined()` conditions in function like macros are not handled correctly.\r\n\r\nminimal example, which expects `__FOO__` to be defined or not.\r\n```\r\n#include \u003cstdio.h>\r\n#define macro(var) (defined(__ ## var ## __))\r\n\r\nint main(void) {\r\n #if macro(FOO)\r\n printf(\"__FOO__ defined\\r\\n\");\r\n #else\r\n printf(\"__FOO__ not defined\\r\\n\");\r\n #endif\r\n return 0;\r\n}\r\n```\r\n\r\npreprocessing with gcc gives:\r\n```\r\n# gcc -D__FOO__ -E test.c\r\n[...]\r\nint main (void) {\r\n printf(\"__FOO__ defined\\r\\n\");\r\n return 0;\r\n}\r\n```\r\n\r\npreprocessing with simplecpp gives\r\n```\r\n# simplecpp -D__FOO__ -E test.c\r\nint main ( void ) {\r\n printf( \"__FOO__ not defined\\r\\n\" ) ;\r\n return 0 ;\r\n}\r\n```\r\n\r\nThe real world code i encountered the problem with is in [parts.h](https://github.com/ARMmbed/mbed-hal-atmel-common/blob/master/source/utils/parts.h) of atmel software framework. They expect the user to define the chip, software is being compiled for, as `__chipname__` and derive family, series and product line from this.\r\n\r\nshort excerpt to clarify:\r\n```\r\n#define SAM_PART_IS_DEFINED(part) (defined(__ ## part ## __))\r\n [...]\r\n\r\n/* SAM4S series */\r\n#define SAM4S16 ( \\\r\n SAM_PART_IS_DEFINED(SAM4S16B) || \\\r\n SAM_PART_IS_DEFINED(SAM4S16C) \\\r\n )\r\n[...]\r\n\r\n/* SAM4S Family */\r\n#define SAM4S (SAM4S2 || SAM4S4 || SAM4S8 || SAM4S16 || SAM4SA16 || SAM4SD16 || SAM4SD32)\r\n[...]\r\n\r\n/* SAM product line */\r\n#define SAM (SAM3S || SAM3U || SAM3N || SAM3XA || SAM4S || SAM4L || SAM4E || \\\r\n SAM0 || SAM4N || SAM4C || SAM4CM || SAM4CP || SAMG)\r\n```\r\nSo if `__SAM4S16C__` was defined by `-D__SAM4S16C__` the macros `SAM4S16`, `SAM4S` and `SAM` are expected to be set to `1`","author":{"url":"https://github.com/illu89","@type":"Person","name":"illu89"},"datePublished":"2017-06-01T08:03:20Z","url":"https://github.com/cppcheck-opensource/simplecpp/issues/75"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:067b3a07-6d87-78b5-0e69-88b5b9cee62f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF48:1D36CE:3CC82C:53D5B7:6AFC51CF |
| html-safe-nonce | fc1d5aa3391063162cb4b403aeb5c2b93d4a628fe0fba85990b83595c840cf13 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjQ4OjFEMzZDRTozQ0M4MkM6NTNENUI3OjZBRkM1MUNGIiwidmlzaXRvcl9pZCI6Ijc5NTk4NTU3MTg4NzYzMzY1OTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 40849a6e3173bbe8d98152ba9778028e233aaa5298fd16ac55b74ec359de976b |
| hovercard-subject-tag | issue:232796346 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cppcheck-opensource/simplecpp/75/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7f1cbaa43dbb35fd2a8f6bc9dfd2688fec82499eb3b31bcda200ef66c863997/cppcheck-opensource/simplecpp/issues/75 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7f1cbaa43dbb35fd2a8f6bc9dfd2688fec82499eb3b31bcda200ef66c863997/cppcheck-opensource/simplecpp/issues/75 |
| og:image:alt | defined() conditions in function like macros are not handled correctly. minimal example, which expects __FOO__ to be defined or not. #include |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | illu89 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b63557e0027d8014589e873df28328da74a4356701bb1a9eab49dbf012ba8fa6 |
| turbo-cache-control | no-preview |
| go-import | github.com/cppcheck-opensource/simplecpp git https://github.com/cppcheck-opensource/simplecpp.git |
| octolytics-dimension-user_id | 278097703 |
| octolytics-dimension-user_login | cppcheck-opensource |
| octolytics-dimension-repository_id | 33434464 |
| octolytics-dimension-repository_nwo | cppcheck-opensource/simplecpp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33434464 |
| octolytics-dimension-repository_network_root_nwo | cppcheck-opensource/simplecpp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0243355b0352c83733a042e0dfb3d75149b51261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width