Community
cancel
Showing results for 
Search instead for 
Did you mean: 
brnprasad630
Beginner
37 Views

Intel(R) C++ 11.1.051 gives Warning warning #1684: conversion from pointer to same-sized integral type (potential portability problem)

Hi All,

I am working on a project where we are using Intel C++ 11.1.051 compiler to comple a VC++ application. This application is being ported from 32bit Windows OS to 64bit Win7 os.

If I build the application using visual C++ compiler with the project option /Wp64 for detecting 64bit portability issues it is building the application properly with out any warnings/errors.

But when i use the intel compiler and use the project option /Wp64 for detecting 64bit portability issues it is showing the

"Warning warning #1684: conversion from pointer to same-sized integral type (potential portability problem)".

This error while using the

#define pcOffset(member) offsetof(PrimaryCmdStruct, member)

offsetof is the macro definition in the header file stddef.h.

In our code we care using DWORD_PTR for accressing the address being returned by the pcOffset definition.
I tried in many ways to fix it but in vain.

I am not finding any issues in 32-bit system.

If anybody found this problem before please suggest me how to go about this issue.

Thanks in advance,
BRN Prasad.
0 Kudos
2 Replies
Milind_Kulkarni__Int
New Contributor II
37 Views

I reproduced your warning with /Wp64 (which comes with any Windows version, and any Intel C++ compiler version).

I looked that in stddef.h , offsetof is defined as :--

#ifdef _WIN64

#define offsetof(s,m) (size_t)( (ptrdiff_t)&(((s *)0)->m) )

#else

#define offsetof(s,m) (size_t)&(((s *)0)->m)

#endif

I believe the definition only of offsetof(...) is causing this warning to appear.
Since ptr type is being converted to size_t , which itself is unsigned __int64 in WIN64.

In this case, rest assured, this warning should not cause much trouble , since size_t (which is typedef'ed appropriately) generally has the size of pointer in either 32-bit or 64-bit system.

If in all cases, if you assure yourself, that the conversion from pointer to integral type is not losing the bits, like for eg. when you do something like:-- (int)(int*)9 , then you can avoid any runtime problems.

And offsetof definition in my and most Windows systems seem to be clean enough to get across portability flaws.

Though I still do not know why all Intel compilers display this warning for the clean typecastings too, and will check out with someone.



TimP
Black Belt
37 Views

The warning comes out due to the compiler not knowing whether the integer data type will be made consistent with pointer, should you shift to a 64-bit system. It doesn't refer back to the typedefs invoked in the macro.
I have had customers who refused to accept a size_t differing from int or long, as they didn't want to be required to consider distinctions. Unfortunately, such a distinction is a feature of all 64-bit Windows systems.