473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

error C2040: 'hFlag' : 'void *' differs in levels of indirection from 'int'

I am using a global which is a void*

I have it defined in one file as:
void* hFlag;

and one other header file as:
extern void* hFlag;

But I get this compile error:

error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'

I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?

Feb 12 '07 #1
6 13675
Angus wrote:
I am using a global which is a void*

I have it defined in one file as:
void* hFlag;

and one other header file as:
extern void* hFlag;

But I get this compile error:

error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'

I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?
Your problem is on line 42. (How can we diagnose such a vague problem?)

If I had to guess, you're probably trying to add an int to a void*.
Don't do that.
--
Clark S. Cox III
cl*******@gmail.com
Feb 12 '07 #2
Angus a écrit :
I am using a global which is a void*

I have it defined in one file as:
void* hFlag;

and one other header file as:
extern void* hFlag;

But I get this compile error:

error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'

I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?
From
http://msdn2.microsoft.com/en-us/library/kb3dky0e.aspx

Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2040

Error Message
'operator' : 'identifier1' differs in levels of indirection from
'identifier2'

An expression involving the operators has inconsistent levels of
indirection.

If both operands are arithmetic or both are nonarithmetic (such as array
or pointer), they are used without change. If one operand is arithmetic
and the other is not, the arithmetic operator is converted to the
nonarithmetic type.

This can happen when you pass a void * to a function that is expecting
an integer.
Feb 12 '07 #3
jacob navia <ja***@jacob.remcomp.frwrites:
Angus a écrit :
>I am using a global which is a void*
I have it defined in one file as:
void* hFlag;
and one other header file as:
extern void* hFlag;
But I get this compile error:
error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'
I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?

From
http://msdn2.microsoft.com/en-us/library/kb3dky0e.aspx

Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2040

Error Message
'operator' : 'identifier1' differs in levels of indirection from
'identifier2'

An expression involving the operators has inconsistent levels of
indirection.

If both operands are arithmetic or both are nonarithmetic (such as
array or pointer), they are used without change. If one operand is
arithmetic and the other is not, the arithmetic operator is converted
to the nonarithmetic type.

This can happen when you pass a void * to a function that is expecting
an integer.
Yes, the web page really says "the arithmetic operator is converted to
the nonarithmetic type". Presumably that should be "arithmetic
operand"; converting an operator doesn't make any sense.

There are no implicit conversions between arithmetic and
non-arithmetic types (except for the special case of a null pointer
constant). Possibly the Visual C++ compiler supports such conversions
as an extension, but it's unwise to depend on them. I seriously doubt
that the text you quoted is going to help the OP solve his problem.

Angus: You need to show us some actual code that exhibits the problem.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 12 '07 #4
Keith Thompson wrote:
jacob navia <ja***@jacob.remcomp.frwrites:
Angus a écrit :
I am using a global which is a void*
I have it defined in one file as:
void* hFlag;
and one other header file as:
extern void* hFlag;
But I get this compile error:
error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'
I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?
From
http://msdn2.microsoft.com/en-us/library/kb3dky0e.aspx

Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2040

Error Message
'operator' : 'identifier1' differs in levels of indirection from
'identifier2'

An expression involving the operators has inconsistent levels of
indirection.

If both operands are arithmetic or both are nonarithmetic (such as
array or pointer), they are used without change. If one operand is
arithmetic and the other is not, the arithmetic operator is converted
to the nonarithmetic type.

This can happen when you pass a void * to a function that is expecting
an integer.

Yes, the web page really says "the arithmetic operator is converted to
the nonarithmetic type". Presumably that should be "arithmetic
operand"; converting an operator doesn't make any sense.

There are no implicit conversions between arithmetic and
non-arithmetic types (except for the special case of a null pointer
constant).
Pointers can be implicitly converted to bool (_Bool) in C99.

Feb 12 '07 #5
On 12 Feb, 12:11, "Angus" <anguscom...@gmail.comwrote:
I am using a global which is a void*

I have it defined in one file as:
void* hFlag;

and one other header file as:
extern void* hFlag;

But I get this compile error:

error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'

I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?
Is the line that it is objecting to, by any chance, something along
the lines of hFlag = malloc(something); ? If so, have you included a
prototype for malloc, eg by including <stdlib.h?

If it's not this then, as others have said, you're going to have to
post the code...

Paul.

Feb 12 '07 #6
On Feb 12, 10:49 pm, gw7...@aol.com wrote:
On 12 Feb, 12:11, "Angus" <anguscom...@gmail.comwrote:
I am using a global which is a void*
I have it defined in one file as:
void* hFlag;
and one other header file as:
extern void* hFlag;
But I get this compile error:
error C2040: 'hFlag' : 'void *' differs in levels of indirection from
'int'
I can't understand what the problem is. I have another global
variable which is not void* and that works ok. I assume void* is the
problem. How can I fix it?

Is the line that it is objecting to, by any chance, something along
the lines of hFlag = malloc(something); ? If so, have you included a
prototype for malloc, eg by including <stdlib.h?

If it's not this then, as others have said, you're going to have to
post the code...
That was my first thought as well. But he should get two warnings for
that:
warning C4013: 'malloc' undefined; assuming extern returning int
warning C4047: 'initializing' : 'void *' differs in levels of
indirection from 'int '
For Jacob's suggestion ("This can happen when you pass a void * to a
function that is expecting
an integer.") he should also get two warnings, a bit different though:
warning C4047: 'function' : 'int ' differs in levels of indirection
from 'void *'
warning C4024: 'fcn' : different types for formal and actual
parameter 1
Hopefully he'll post the code (and more hopefully, he's not compiling
it in C++ mode).
--
WYCIWYG - what you C is what you get

Feb 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: blimeyoreilly | last post by:
Hi I've a small problem .. can anyone figure it out? I am working in VS.NET in C++ with MFC. I have a CWinApp-based class called CTestHarnessApp. I keep getting the 'differs in levels of...
1
by: uday | last post by:
Hi, I am new to visual c++ and I am trying to compile a Decoder project with library in it. I tried to create a win32 console application and tried to add a compiled static library to it. I...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
2
by: Angus | last post by:
I am using a global which is a void* I have it defined in one file as: void* hFlag; and one other header file as: extern void* hFlag;
6
by: newbarker | last post by:
Hello, This program doesn't work and provides me the errror message "error C2040: 'p' : 'std::string' differs in levels of indirection from 'const char *'": #include <string> int main() {
11
by: DrSchwartz | last post by:
Hi all, I defined a struct in the header like this: #define DFI_HASH_TABLE_SIZE_LOG 16 #define DFI_HASH_TABLE_SIZE (1<<DFI_HASH_TABLE_SIZE_LOG) ... typedef struct _s_ip_dfi_hashtable_entry...
3
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
12
by: Amera | last post by:
hi, i wrote a c code which calls a function from mytest,dll this function returns the character "s" . this is my code : #include<stdio.h> #include<windows.h>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.