cast to void* not working with function pointers

I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*) . Below is the sample code, class Test { int a; }; int main() { Test* *p(void **a); void *f=reinterpret_cast<void*>(p); } The above code works well with Visual Studio/x86 compilers. But with ARM compiler, it gives compilation error.

强制转换为void *不能与函数指针一起工作

我想重新解释一个函数指针到一个void *变量中。 函数指针的类型将是Class* (*)(void*) 。 以下是示例代码, class Test { int a; }; int main() { Test* *p(void **a); void *f=reinterpret_cast<void*>(p); } 上述代码适用于Visual Studio / x86编译器。 但是,使用ARM编译器时,会产生编译错误。 不知道为什么。 错误:#694:reinterpret_cast不能丢弃const或其他类型限定符 我读了将一个

Should I use static

Both static_cast and reinterpret_cast seem to work fine for casting void* to another pointer type. Is there a good reason to favor one over the other? Use static_cast : it is the narrowest cast that exactly describes what conversion is made here. There's a misconception that using reinterpret_cast would be a better match because it means “completely ignore type safety and just cast from

我应该使用静态的

static_cast和reinterpret_cast似乎都可以很好地将void *转换为另一种指针类型。 是否有理由相互支持一个? 使用static_cast :这是最精确的转换,可以准确描述在此处进行的转换。 有一种误解认为使用reinterpret_cast会更好地匹配,因为它意味着“完全忽略类型安全性并且只是从A到B”。 但是,这实际上并没有描述reinterpret_cast的效果。 相反, reinterpret_cast具有许多含义,所有这些含义认为“ reinterpret_cast执行

cast to check inheritance at compile time

Regarding this question: When to use reinterpret_cast? I found sth. like this: template<typename T> bool addModuleFactoryToViewingFactory(ViewingPackage::ViewingFactory* pViewingFactory) { static_cast<ModuleFactory*>(reinterpret_cast<T*>(0)); // Inheritance compile time check ... } Is this a good way to check whether T can be casted to ModuleFactory at compile time? I

强制转换以在编译时检查继承

关于这个问题:何时使用reinterpret_cast? 我找到了某事。 喜欢这个: template<typename T> bool addModuleFactoryToViewingFactory(ViewingPackage::ViewingFactory* pViewingFactory) { static_cast<ModuleFactory*>(reinterpret_cast<T*>(0)); // Inheritance compile time check ... } 这是一个很好的方法来检查T是否可以在编译时输出到ModuleFactory ? 我的意思是,要检查程序员是否将有效

Normal Mapping and translation disrupts my lighting

I got a normal mapping issue. I have a texture and a normal texture on each model loaded via the ASSIMP library. I am calculating the tangent vectors on each object with the help of the ASSIMP library so these should be fine. The objects work perfectly with normal mapping but as soon as I start translating one of the objects (thus influence the Model matrix with translations) the lighting fail

法线贴图和转换会中断我的照明

我有一个正常的映射问题。 对于通过ASSIMP库加载的每个模型,我都有纹理和正常纹理。 我正在ASSIMP库的帮助下计算每个对象上的切线向量,所以这些应该没问题。 这些对象与法线贴图完美配合,但只要我开始翻译其中一个对象(从而影响带翻译的模型矩阵),灯光就会失效。 正如您在图像上看到的那样,地板(沿y轴向下翻转)似乎失去了大部分漫射照明,并且其镜面光照方向错误(应该在灯泡和玩家位置之间) 这可能与正常矩阵有

C++11 user

This question already has an answer here: Representing big numbers in source code for readability? 5 answers This is not possible with user defined literals in the C++11 version of the language as it is right now. User defined literals support a limited format for parameters, doesn't seem to support a right side parameter, chaining, plus there is the problem of representing numbers that

C ++ 11用户

这个问题在这里已经有了答案: 在源代码中代表大数字以提高可读性? 5个答案 用户定义的文字在C ++ 11版本的语言中是不可能的,因为它现在就是这样。 用户定义的文字支持参数的有限格式,似乎不支持右侧参数,链接,此外还存在将0开头的数字表示为实际数字的问题。 所以这是一个不行。 您目前的方法将_000等定义为独立文字,因此编译器只能与他们一起工作,而不能与其他工作。 它不像_是运营商和000是一些参数,您可以

Group the similar boxes

I have a set of (X,Y) coordinates which split a unit square into sub-rectangles. Suppose my coordinates are - ( x1, y1) ( x2, y2) (0.0000,0.0000) (0.3412,0.4175) (0.7445,0.0000) (1.0000,0.6553) (0.7445,0.6553) (1.0000,1.0000) (0.0000,0.6553) (0.7445,1.0000) (0.3412,0.0000) (0.7445,0.4175)

分组类似的盒子

我有一组(X,Y)坐标,将单位正方形分成子矩形。 假设我的坐标是 - ( x1, y1) ( x2, y2) (0.0000,0.0000) (0.3412,0.4175) (0.7445,0.0000) (1.0000,0.6553) (0.7445,0.6553) (1.0000,1.0000) (0.0000,0.6553) (0.7445,1.0000) (0.3412,0.0000) (0.7445,0.4175) (0.3412,0.4175) (0.7445,0.6553)

How do I best silence a warning about unused variables?

I have a cross platform application and in a few of my functions not all the values passed to functions are utilised. Hence I get a warning from GCC telling me that there are unused variables. What would be the best way of coding around the warning? An #ifdef around the function? #ifdef _MSC_VER void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal qrLeft, qreal qrT

我如何最好地保持对未使用变量的警告?

我有一个跨平台的应用程序,在我的一些函数中,并不是所有传递给函数的值都被使用。 因此,我从GCC得到一个警告,告诉我有没有使用的变量。 对警告进行编码的最佳方式是什么? 函数的#ifdef? #ifdef _MSC_VER void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal qrLeft, qreal qrTop, qreal qrWidth, qreal qrHeight) #else void ProcessOps::sendToExternalApp(QString sAppName, QString

Will a "variableName;" C++ statement be a no

In C++ sometimes a variable will be defined, but not used. Here's an example - a function for use with COM_INTERFACE_ENTRY_FUNC_BLIND ATL macro: HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ ) { DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug DEBUG_LOG( iid ); iid; // <<<<<<

将一个“variableName;” C ++语句是一个没有

在C ++中有时会定义一个变量,但不会使用。 下面是一个示例 - 一个用于COM_INTERFACE_ENTRY_FUNC_BLIND ATL宏的函数: HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ ) { DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug DEBUG_LOG( iid ); iid; // <<<<<<<----silence compiler warning i

Universally compiler independent way of implementing an UNUSED macro in C/C++

When implementing stubs etc. you want to avoid "unused variable" warnings. I've come across a few alternatives of UNUSED() macros over the years, but never one which either is proven to work for "all" compilers, or one which by standard is air tight. Or are we stuck with #ifdef blocks for each build platform? EDIT: Due to a number of answers with non c-compliant alter

在C / C ++中实现UNUSED宏的通用编译器独立方式

在实施存根等时,您希望避免“未使用的变量”警告。 我在过去几年中遇到过一些UNUSED()宏的替代方案,但从来没有一个方法被证明适用于“全部”编译器,或者是标准的密封编译器。 或者我们坚持每个构建平台都使用#ifdef块? 编辑:由于一些答案与非C兼容的替代品,我想澄清,我正在寻找一个定义,这是一个有效的C和C + +,所有的味道等。 根据此答案由用户GMAN典型的方式是强制转换为void : #define UNUSED(x) (void)(x)

macros defined in linux kernel.h file

On stack overflow I ran into a question What is ":-!!" in C code? > #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) > #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) out of curiosity I want to know how can I use these kind of macros ? int main() { BUILD_BUG_ON_ZERO(0); return 0; } In the above code it gives an error that type name i

在linux kernel.h文件中定义的宏

在堆栈溢出我遇到了一个问题什么是“: - !!” 在C代码? > #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) > #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) 出于好奇,我想知道如何使用这些宏? int main() { BUILD_BUG_ON_ZERO(0); return 0; } 在上面的代码中,它给出了一个错误,即类型名称是不允许的。 编辑:代码编译在Linux上使用GCC但在视觉工作室失败