-
Notifications
You must be signed in to change notification settings - Fork 123
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
Fix compilation error C4576 with C++ and MSVC 2019 (19.28.29913) #1885
Conversation
Thank you for your contribution hwmaier! We will review the pull request and get back to you soon. |
We might have this pattern used elsewhere within the SDK. @hwmaier was this the only instance you found? I wonder if we should add this scenario of consuming the C SDK in a C++ app, using a C++ compiler within CI to catch such issues going forward. cc @danieljurek |
@CaseyCarter and @barcharcraz should the MSVC compiler be complaining about this? I don't fully understand the issue here, maybe you can shed some light on the topic. |
Hi @ahsonkhan , I only used so far the JSON components of the SDK, so I cannot comment if other header files have similar issues with VS 2019. Interestingly gcc 9 and gcc 10 do not complain about it. While I understand that there is also a C++ SDK, there are instances where the C API has to be consumed in a C++ application. In our scenario our C++ application consumes Azure NetXDuo which contains this SDK as a subcomponent, From my understanding the cast is redundant and unnecessary, hence I suggest to remove it. |
This construct - Compound literals are not valid syntax in C++, but accepted by some C++ compilers (clearly not MSVC) as an extension except (IIRC) that those C++ compilers treat the compound literal as a prvalue expression of type There seems to be absolutely no point to the use of compound literals here - why initialize by copying from a compound literal when we can initialize directly? |
@CaseyCarter should we make this a coding guideline and fix the pattern across the SDK? We have other instances in our client libraries, like:
cc @danewalton, @antkmsft Also, @danieljurek is there any way for us to add CI leg for this MSVC version so we always stay green, even though it is a C++ compiler, and I am not sure if this scenario is one we actively intend to support for Embedded C. I will file issues to track this change shortly :) |
This is news to me, and I assume @barcharcraz as well? We would not have encouraged using constructs outside the common subset of C and C++ in C SDKs if consuming those SDKs from C++ is a requirement. |
@hwmaier - just so I understand it better, can you share more info about your scenario and application use case? What drove the decision to write your app in C++ instead of C, while using things like NetXDuo? And, with this fix, are you unblocked now? Are you able to consume Azure NetxDuo (and indirectly this SDK) successfully? |
@ahsonkhan This is a surprising question. C++ is a modern programming language with OOP concepts and a template class standard library which implement modern design patterns like containers and algorithms. The productivity benefits of using C++ over plain old C in software design are tremendous and I believe well accepted in the software industry. NetXDuo is not available as C++ version as most RTOS aren't and that is the benefit of C++ that you can consume C libraries and C API without problem. |
Using C++ over C due to the productivity and modern language features for app development, certainly make sense :) As an aside: Which platforms do you expect your C++ app to run? Are they intended for desktop platforms/OSes like Windows, Linux, MacOS, or for particular embedded devices? And, other than MSVC, what are the compilers you use for building, if any? |
@ahsonkhan To be quite frank, we use C++ in all our products, embedded or not. We remove exception handling for embedded platform as this is expensive and some of the more complex containers. We have written C++ wrappers for ThreadX/NetXDuo's RTOS API which mimic the C++ STL API. So we have code which is multiplatform. Embedded on Azure RTOS using gcc and MSVC and MSVC on Windows and gcc on Linux. Azure RTOS with MSVC we mainly use to develop as we run the whole RTOS stack on Windows which gives us a very fast compile/run/debug cycle. Essentially we can develop most of the embedded code on Windows. |
When using this SDK with MS C++ 2019 (19.28.29913), including the header file
az_json.h
into a C++ file yields the following error:Example code to reproduce:
compile above using this command line from VS 2019 command prompt:
Removing the redundant C-style type casts in the initialisers fixes this compilation error.