Suppress anonymous structs warning with Clang - "-fms-extensions" doesn't work - visual-c++

I have an Xcode project that I compile with Clang using some 3rd party library with Visual Studio C code.
In the 3rd party library anonymous structs are used in header files (I can't really change that). Thus I get this warning:
"myfile.h:47:17: Anonymous structs are a GNU extension"
As described here, I tried to pass "-fms-extensions" in the C flags of my Xcode project:
http://clang.llvm.org/docs/UsersManual.html#microsoft-extensions
No luck. Any idea how to get rid of that warning?

Adding -Wno-microsoft did not work for me.
Using this small test program
typedef struct test_struct
{
struct
{
int a;
int b;
};
int x;
} Test;
int main(int argc, char **argv)
{
Test test;
test.a = 0;
}
using -Wno-gnu disables the warning
Version is Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

You can simply use -Wno-microsoft to hide the warning.

Related

stack overflow by using to big structure? (C) ARM M3

is it possible that a structure in a main.c is so big, that its values cant be stored correctly?
How can I check what the reason is?
myStructure.x= 122; myStructure.a= 2;
reading out
printf("%d", myStructure.a); "a"
I declared it globally and then its values were stored correctly.
What is the difference declaring it globally?
It was on a microcontroller ARM M3.
Thank you.
I tried to debug it step by step. But there was no clue why it behaves like that. Just writing wrong values..
So I just the same structure but this time globally. And it worked.
I checked the code and I saw that this global variable is once declared extern
Minimal example:
file1.c
extern originalStruct myGlobalStruct;
file2.c
originalStruct{
int a;
int z;
}
main.c
int main(){
originalStruct myLocalStr;
//reading sensor data:
myLocalStr.a=readInSensor();
myLocalStr.z= readInSensor();
//
myGlobalStruct.a=readInSensor();
myGlobalStruct.z= readInSensor();
//show Struct Values:
// (also with gdb debugger)
printStruct(myLocalStr);// doesnt delivier the right values
printStruct(myGlobalStr); // does deliver the right values
return 1;}
Maybe you have not declared the stack correctly. You have to define the stack in the linker script.

MSVC compiler error for external variables and OpenMP's threadprivate

I am trying to compile a c++ application using MSVC (Compiler Version 19.32.31329 for x86). The author of the application has complied it successfully using GCC 8.3, 9.3, and 10.3.
I run into an error when I enable OpenMP for parallel computing - in particular in the random.h and random.cpp files. I have found a small code snippet that throws the same compile error on MSVC but has no issues when compiled with GCC according to the author.
#include<omp.h>
#include<iostream>
struct point2d
{
int x;
int y;
#ifndef DECLARE_AS_POD_TYPE
point2d() {}
#endif
};
int main(int argc, char* argv[])
{
using namespace std;
extern point2d myPoint;
#pragma omp threadprivate(myPoint)
//point2d myPoint;
myPoint.x = omp_get_thread_num();
cout << myPoint.x << endl;
}
The MSVC error I get is error C3053: 'myPoint': 'threadprivate' is only valid for global or static data items
I am pretty new to OpenMP but have done a fair amount of googling. I am not the first person to have this issue but I have not found a solution that works for me. In particular, I have looked at:
Using threadprivate directive in Visual Studio
Threadprivate directive after external declaration of global variables
OpenMP threadprivate directive is not working.
I am using this application as a bit of a learning exercise so I am happy to make changes to the code but I have tried quite a few permutations and I am not able to make progress.
Any suggestions are welcome.

Error UnityEngine.XR.WSA.Input.InteractionManager::GetCurrentReading_Internal

I am working to create a Hololens application using Vuforia for the Tracking system and MRTK for the interaction with the objects. The problem comes when mounting the solution in Visual Studio, I can not run because I get the following error. specifically a breakpoint in int32_t retVal = _il2cpp_icall_func (___ sourceStates0);
If I work separately, in principle I have no problems. but when I put them together, I get this error.
// System.Int32 UnityEngine.XR.WSA.Input.InteractionManager::GetCurrentReading_Internal(UnityEngine.XR.WSA.Input.InteractionSourceState[])
extern "C" IL2CPP_METHOD_ATTR int32_t InteractionManager_GetCurrentReading_Internal_m48B784A597B956AF326A4DCB9C00F2AACF4C62A7 (InteractionSourceStateU5BU5D_tB8FF9D808295324B506769A009A5BD2C5CD671EA* ___sourceStates0, const RuntimeMethod* method)
{
typedef int32_t (*InteractionManager_GetCurrentReading_Internal_m48B784A597B956AF326A4DCB9C00F2AACF4C62A7_ftn) (InteractionSourceStateU5BU5D_tB8FF9D808295324B506769A009A5BD2C5CD671EA*);
static InteractionManager_GetCurrentReading_Internal_m48B784A597B956AF326A4DCB9C00F2AACF4C62A7_ftn _il2cpp_icall_func;
if (!_il2cpp_icall_func)
_il2cpp_icall_func = (InteractionManager_GetCurrentReading_Internal_m48B784A597B956AF326A4DCB9C00F2AACF4C62A7_ftn)il2cpp_codegen_resolve_icall ("UnityEngine.XR.WSA.Input.InteractionManager::GetCurrentReading_Internal(UnityEngine.XR.WSA.Input.InteractionSourceState[])");
int32_t retVal = _il2cpp_icall_func(___sourceStates0);
return retVal;
}
What version of Unity, MRTK and Vuforia are you using? This is an error inside of Unity and knowing the specific versions may help identify the issue?
Thanks!

Visual Studio 2015 doesn't honour _Check_return_ or _Must_inspect_result_

I have a cross-platform build. On a *nix platform using GCC, I use the __attribute__((warn_unused_result)) to notify the consumer of my API if a return value is not checked. I assumed that _Check_return does the same thing on MSVC, but it doesn't appear to be working the way I expect.
The following code does not produce a warning as I expect. Warnings are set to /Wall.
_Check_return_ _Must_inspect_result_ int foo()
{
return 100;
}
int main()
{
foo();
return 0;
}
Code compiles without warnings. What am I doing wrong (or what should I be using to generate warnings for unchecked return codes)?
SAL annotations like _Check_return_ and _Must_inspect_result_ are only checked during code analysis builds (either by starting a code analysis build in the IDE or by building with the /analyze flag on the command line).
See "Understanding SAL" on MSDN for more information.

call unmanaged C++ code from C# using pinvoke

I have a unmanaged C++ dll for which I do not have access to code but have all methods declarations for.
Lets for simplicity say that .h looks like this:
#include <iostream>
#ifndef NUMERIC_LIBRARY
#define NUMERIC_LIBRARY
class Numeric
{
public:
Numeric();
int Add(int a, int b);
~Numeric();
};
#endif
and method implementation in .cpp file
int Numeric::Add(int a, int b)
{
return (a + b);
}
I simply want to call the add function from C++ in my C# code:
namespace UnmanagedTester
{
class Program
{
[DllImport(#"C:\CPP and CSharp Project\UnmanagedNumeric\Debug\numeric.dll", EntryPoint = "Add")]
public static extern int Add(int a, int b);
static void Main(string[] args)
{
int sum = Add(2, 3);
Console.WriteLine(sum);
}
}
}
After trying to execute I have the following error:
Unable to find an entry point named 'Add' in DLL 'C:\CPP and CSharp Project\UnmanagedNumeric\Debug\numeric.dll'.
I CAN NOT change C++ code. Have no idea what is going wrong.
Appreciate your help.
Using PInvoke you can only call global functions exported from Dll. To use exported C++ classes, you need to write C++/CLI wrapper. This is C++/CLI Class Library project, which exposes pure .NET interface, internally it is linked to unmanaged C++ Dll, instantiates a class from this Dll and calls its methods.
Edit: you can start from this: http://www.codeproject.com/KB/mcpp/quickcppcli.aspx#A8
If you need to create a wrapper, take a look at swig.org. It will generate one for most high level language like C#.
I just came across this program a few minutes ago while working the same problem that you are.
To use a class from native C++ from C# you need a C++/CLi wrapper in between, as mentioned by by previous answers. To actually do that, it is not very straight forward. Here is I link that tell you how to do it at a high level: C++/CLI wrapper for native C++ to use as reference in C#.
If you are quite new to this (like me), you might stumble on 1) -- the linking part. To solve that, you can see how I did here (see my question portion): Link error linking from managed to unmanaged C++ despite linking to .lib file with exported symbols

Resources