473,386 Members | 1,699 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,386 software developers and data experts.

pointer truncation from 'void *' to 'int'

Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?

Nov 15 '05 #1
26 7659
>Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


You are worried about whether converting void* to int really involves
truncation? I am new to C, but it seems that sizeof would answer this
question for you. I imagine that the space required for pointers would
vary from one machine to another, depending on the total amount of
available memory, while the size of int would more likely just match
the IEEE recommendation.

Nov 15 '05 #2
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Because sizeof(void*) doesn't necessarily equal to sizeof(int) nor
sizeof(void(*)()), it's all platform dependent (and sometimes even compiler
dependent). And, although a pointer is an integer address of a memory cell,
semantically its a very different type from an integer, so you shouldn't
expect the compiler eat your code and doesn't eructate.

Alex
Nov 15 '05 #3
Alfonso Morra wrote:
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
That, I believe, is a constraint violation, i.e. an error. There is also
no guarantee that even if you cast the value it will actually fit in an int.
Pointers are stored as ints (is that right?),
Wrong. Pointer are stored as pointers. These could be the same size as
ints, larger or smaller. Pointers to consecutive locations could also,
which converted to a suitable integer type, not be consecutive integers.
so as AFAIK, there is
nothing to worry about is there?
There is everything to worry about. Your program is wrong, non-portable,
and quite likely to break as soon as you try to compile for a 64 bit
target. There you could find (depending on the model used) that pointers
are 64 bits wide whilst int is only 32 bits wide, and there is no
guarantee that *any* integer type is wide enough.
I'm using VC 7.1

Why are such assignments being treated as errors?


Because they are errors. Whatever you are trying to do, you are almost
certainly doing it the wrong way.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #4
Alfonso Morra wrote:
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


There is no guarantee that pointers on your implementation are even
representable as int. Pointer to int conversion is implementation
defined and as such cannot be relied upon.

-- Denis
Nov 15 '05 #5
Alfonso Morra wrote on 24/07/05 :
I'm getting a compiler error of "pointer truncation from 'void *' to 'int'"
because I'm not explicitly casting from void* to (datatype*). Pointers are
stored as ints (is that right?),
Saiz who ? This statement is plain wrong. Pointers are stored as ...
pointers.
so as AFAIK, there is nothing to worry about
is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Because they are potential errors. In a 16 bit x386 machine, you can
have 16-int and 32-bit pointers.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"
Nov 15 '05 #6
Alfonso Morra wrote:
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?),
Wrong. Pointers are stored as pointers.
so as AFAIK, there is
nothing to worry about is there?
Yes, there is.
I'm using VC 7.1

Why are such assignments being treated as errors?


Because they are erroneous.
Nov 15 '05 #7

"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Altough the C standard doesn't say so, *most* (99.9%) of C implementations
have sizeof(long)==sizeof(void *),
so you can convert pointer to long and back again.
Nov 15 '05 #8

"Charles F McDevitt" <Ch************@comcast.net> wrote in message
news:ld********************@comcast.com...

"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Altough the C standard doesn't say so, *most* (99.9%) of C implementations
have sizeof(long)==sizeof(void *),
so you can convert pointer to long and back again.


Oopss.. I means to say sizeof(long)>=sizeof(void *)
Nov 15 '05 #9
Charles F McDevitt wrote:
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?

Altough the C standard doesn't say so, *most* (99.9%) of C implementations
have sizeof(long)==sizeof(void *),


Balderdash.

Besides, what has sizeof got do do with it? If sizeof(void*)
happens to equal sizeof(float) or sizeof(double), what conclusion
can you draw about interconvertibility?

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #10
On Sun, 24 Jul 2005 13:49:49 +0000 (UTC), Alfonso Morra
<sw***********@the-ring.com> wrote:
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Converting from void* to datatype* does not involve any integer
conversion. Furthermore, a cast is not necessary. Your assumption
about the cause of the error message is suspect.
Pointers are stored as ints (is that right?), so as AFAIK, there is
While the representation of a pointer value may coincide with the
representation of an integer value, the two types are completely
distinct. Pointers are stored in objects with type pointer to T and
integers are stored in objects with type int (or long or short, etc).
nothing to worry about is there?
If there was nothing to worry about, the compiler would probably not
be bringing it to your attention (though not universally true). In
this case, it definitely is something to worry about.

I'm using VC 7.1
Probably not relevant.

Why are such assignments being treated as errors?


You apparently did something unintended. Show us your code.
<<Remove the del for email>>
Nov 15 '05 #11
"Charles F McDevitt" <Ch************@comcast.net> writes:
"Charles F McDevitt" <Ch************@comcast.net> wrote in message
news:ld********************@comcast.com...

[...]
Altough the C standard doesn't say so, *most* (99.9%) of C implementations
have sizeof(long)==sizeof(void *),
so you can convert pointer to long and back again.


Oopss.. I means to say sizeof(long)>=sizeof(void *)


Which means you can write code that will fail mysteriously as soon as
it's ported to a system where sizeof(long) < sizeof(void*).

Or you can write portable code that will work on any platform.

The language allows conversions between pointers and integers, but
there's rarely any good reason to use such conversions. 99.9% of the
time, it's better just to treat pointers as pointers.

--
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.
Nov 15 '05 #12
"Alexei A. Frounze" <al*****@chat.ru> writes:
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Because sizeof(void*) doesn't necessarily equal to sizeof(int) nor
sizeof(void(*)()), it's all platform dependent (and sometimes even compiler
dependent). And, although a pointer is an integer address of a memory cell,
semantically its a very different type from an integer, so you shouldn't
expect the compiler eat your code and doesn't eructate.


No, a pointer is not necessarily an integer address of a memory cell.
It is on many systems, but the standard makes no such guarantee, and
there are real-world systems where the assumption breaks down.

--
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.
Nov 15 '05 #13
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
....
No, a pointer is not necessarily an integer address of a memory cell.
It is on many systems, but the standard makes no such guarantee, and
there are real-world systems where the assumption breaks down.


What is it then? Just give a few examples.

Alex
Nov 15 '05 #14
On Mon, 25 Jul 2005 00:00:17 +0400, "Alexei A. Frounze"
<al*****@chat.ru> wrote:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
...
No, a pointer is not necessarily an integer address of a memory cell.
It is on many systems, but the standard makes no such guarantee, and
there are real-world systems where the assumption breaks down.


What is it then? Just give a few examples.


In the old DOS 16-bit world, there were near and far pointers. Far
pointers had an offset added in, IIRC. It was possible for different
"integer" values to point to the same address.
--

Best wishes,

Bob
Nov 15 '05 #15
Alexei A. Frounze wrote on 24/07/05 :
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
...
No, a pointer is not necessarily an integer address of a memory cell.
It is on many systems, but the standard makes no such guarantee, and
there are real-world systems where the assumption breaks down.


What is it then? Just give a few examples.


How is 1234:4567 an integer ?

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
Nov 15 '05 #16
"Robert W Hand" <rw****@NOSPAMoperamail.com> wrote in message
news:lq********************************@4ax.com...
On Mon, 25 Jul 2005 00:00:17 +0400, "Alexei A. Frounze"
<al*****@chat.ru> wrote:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
...
No, a pointer is not necessarily an integer address of a memory cell.
It is on many systems, but the standard makes no such guarantee, and
there are real-world systems where the assumption breaks down.


What is it then? Just give a few examples.


In the old DOS 16-bit world, there were near and far pointers. Far
pointers had an offset added in, IIRC. It was possible for different
"integer" values to point to the same address.


As Emmanuel suggested 0x1234:0x5678 :), I can agree it's not really a
number, at least when written like this (unless : represents division :).
But if we're really talking about converting real mode far pointers to
integers, the usual result of converting 0x1234:0x5678 to unsigned long
would be 0x12345678, which however does not represent directly a valid
(physical) address in the real mode address range, still is some number and
the backconversion is possible w/o loss of the info. OK, is there anything
else but the segmentation/page translation to consider? Something really
odd?

Alex
Nov 15 '05 #17
"Alexei A. Frounze" <al*****@chat.ru> writes:
"Robert W Hand" <rw****@NOSPAMoperamail.com> wrote in message
news:lq********************************@4ax.com...
On Mon, 25 Jul 2005 00:00:17 +0400, "Alexei A. Frounze"
<al*****@chat.ru> wrote:
>"Keith Thompson" <ks***@mib.org> wrote in message
>news:ln************@nuthaus.mib.org...
>...
>> No, a pointer is not necessarily an integer address of a memory cell.
>> It is on many systems, but the standard makes no such guarantee, and
>> there are real-world systems where the assumption breaks down.
>
>What is it then? Just give a few examples.


In the old DOS 16-bit world, there were near and far pointers. Far
pointers had an offset added in, IIRC. It was possible for different
"integer" values to point to the same address.


As Emmanuel suggested 0x1234:0x5678 :), I can agree it's not really a
number, at least when written like this (unless : represents division :).
But if we're really talking about converting real mode far pointers to
integers, the usual result of converting 0x1234:0x5678 to unsigned long
would be 0x12345678, which however does not represent directly a valid
(physical) address in the real mode address range, still is some number and
the backconversion is possible w/o loss of the info. OK, is there anything
else but the segmentation/page translation to consider? Something really
odd?


I seem to recall that pointers (at least function pointers) on the IBM
AS/400 are rather odd beasts. I don't know the details.

On Cray vector machines, word pointers are memory addresses (that look
like integers), but byte pointers have an offset in the high-order
bits. Code that attempts to treate pointers as integers fails.

--
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.
Nov 15 '05 #18
In article <3k************@individual.net>
Alexei A. Frounze <al*****@chat.ru> wrote:
As Emmanuel suggested 0x1234:0x5678 :), I can agree it's not really a
number, at least when written like this (unless : represents division :).
But if we're really talking about converting real mode far pointers to
integers, the usual result of converting 0x1234:0x5678 to unsigned long
would be 0x12345678 ...
Unless you do it by computing the real physical address in memory,
in which case it is (0x1234 << 4) + 0x5678 = 0x179b8.
... [but] is there anything else but the segmentation/page translation
to consider? Something really odd?


There is always the IBM AS/400, with its 128-bit pointers, of which
many bits are reserved to the system.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 15 '05 #19
On 24 Jul 2005 07:17:01 -0700, "Eric Lavigne" <la**********@gmail.com>
wrote in comp.lang.c:
Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).
Pointers are stored as ints (is that right?), so as AFAIK, there is
nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


You are worried about whether converting void* to int really involves
truncation? I am new to C, but it seems that sizeof would answer this
question for you. I imagine that the space required for pointers would
vary from one machine to another, depending on the total amount of
available memory, while the size of int would more likely just match
the IEEE recommendation.


There is no IEEE standard that governs the size of an int in C, and
even if there were, it would not override the C standard.

There is one and only one requirements for the type int in C, and that
is it must be able to contain all values in the range of -32767 to
+32767.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #20
Keith Thompson wrote:
"Alexei A. Frounze" <al*****@chat.ru> writes:
"Alfonso Morra" <sw***********@the-ring.com> wrote in message

I'm getting a compiler error of "pointer truncation from 'void *'
to 'int'" because I'm not explicitly casting from void* to
(datatype*). Pointers are stored as ints (is that right?), so as
AFAIK, there is nothing to worry about is there?

I'm using VC 7.1

Why are such assignments being treated as errors?


Because sizeof(void*) doesn't necessarily equal to sizeof(int) nor
sizeof(void(*)()), it's all platform dependent (and sometimes even
compiler dependent). And, although a pointer is an integer address
of a memory cell, semantically its a very different type from an
integer, so you shouldn't expect the compiler eat your code and
doesn't eructate.


No, a pointer is not necessarily an integer address of a memory
cell. It is on many systems, but the standard makes no such
guarantee, and there are real-world systems where the assumption
breaks down.


I have watched this silly "discussion" go on for two days, or so,
an nobody seems to want to bother to tell the poor OP that he
failed to #include <stdlib.h>.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 15 '05 #21


Barry Schwarz wrote:
On Sun, 24 Jul 2005 13:49:49 +0000 (UTC), Alfonso Morra
<sw***********@the-ring.com> wrote:

Hi,

I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).

Converting from void* to datatype* does not involve any integer
conversion. Furthermore, a cast is not necessary. Your assumption
about the cause of the error message is suspect.

Pointers are stored as ints (is that right?), so as AFAIK, there is

While the representation of a pointer value may coincide with the
representation of an integer value, the two types are completely
distinct. Pointers are stored in objects with type pointer to T and
integers are stored in objects with type int (or long or short, etc).

nothing to worry about is there?

If there was nothing to worry about, the compiler would probably not
be bringing it to your attention (though not universally true). In
this case, it definitely is something to worry about.

I'm using VC 7.1

Probably not relevant.

Why are such assignments being treated as errors?

You apparently did something unintended. Show us your code.


Here is a snippet of one of the functions that causes the compiler to
barf (note the language is C++), but I'm not really doing anything C++
specific :
void *SharedMemory::Create(int memsize) {
SharedMemory::HEADER *p = NULL;

/* Code to alloc mem etc */
....
p = (SharedMemory::HEADER *) ((int)p + p->size); //offending line
....
}
<<Remove the del for email>>


Nov 15 '05 #22
Alfonso Morra <sw***********@the-ring.com> wrote:
Here is a snippet of one of the functions that causes the compiler to
barf (note the language is C++), but I'm not really doing anything C++
specific :
Yes, you are. First of all, you're asking about void *s, which behave
differently in C and in C++; C++ sacrificed some usefulness for
theoretical (but not practical) type-safety. Second:
void *SharedMemory::Create(int memsize) { ^^
SharedMemory::HEADER *p = NULL; ^^
p = (SharedMemory::HEADER *) ((int)p + p->size); //offending line

^^
Richard
Nov 15 '05 #23
Charles F McDevitt wrote:
Altough the C standard doesn't say so, *most* (99.9%) of C
implementations have sizeof(long)==sizeof(void *), so you
can convert pointer to long and back again.


Not really. MSVC on AMD64 has, AFAICT,
CHAR_BIT == 8
sizeof(long) == 4
sizeof(void *) == 8

http://www.microsoft.com/whdc/winhec.../64bitAMD.mspx

<quote>
Another bad bit of code casts a pointer to a long. Such code would run
properly on 32-bit Windows, but the pointer will get truncated when you
compile the code for 64-bit Windows.
</quote>

Do you claim the market share of Visual Studio on AMD64/EM64T is
less than 0.1 percent?
Nov 15 '05 #24
Grumble <de*****@kma.eu.org> wrote:
Charles F McDevitt wrote:
Altough the C standard doesn't say so, *most* (99.9%) of C
implementations have sizeof(long)==sizeof(void *), so you
can convert pointer to long and back again.


Not really. MSVC on AMD64 has, AFAICT,
CHAR_BIT == 8
sizeof(long) == 4
sizeof(void *) == 8

http://www.microsoft.com/whdc/winhec.../64bitAMD.mspx

<quote>
Another bad bit of code casts a pointer to a long. Such code would run
properly on 32-bit Windows, but the pointer will get truncated when you
compile the code for 64-bit Windows.
</quote>


Guess where such behaviour is rife, and can hardly be avoided? Right,
the Windows API. Grumble.

Richard
Nov 15 '05 #25
Alfonso Morra wrote:

Here is a snippet of one of the functions that causes the compiler to
barf (note the language is C++), but I'm not really doing anything C++
specific :
Well, there's some dodgy syntax.
void *SharedMemory::Create(int memsize) {
SharedMemory::HEADER *p = NULL;

/* Code to alloc mem etc */
...
p = (SharedMemory::HEADER *) ((int)p + p->size); //offending line


Yes, that line offends. Not only is it offensive, but
it's dumb. Why rely on an unreliable implementation-defined
non-portable conversion when there's a reliable well-defined
fully portable alternative?

p = (SharedMemory::HEADER*) ((char*)p + p->size);

Shoving pointy sticks up my nose improves my disposition,
because it feels *so* good when I stop.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #26
Alfonso Morra writes:
I'm getting a compiler error of "pointer truncation from 'void *' to
'int'" because I'm not explicitly casting from void* to (datatype*).

Here is a snippet of one of the functions that causes the compiler to
barf (note the language is C++), but I'm not really doing anything C++
specific :


As Richard has already pointed out, those :: namespace operators
indicate that you certainly *are* doing something C++ specific!
SharedMemory::HEADER *p = NULL;
/* Code to alloc mem etc */
p = (SharedMemory::HEADER *) ((int)p + p->size); //offending line


What in the world are you trying to do here?! You're taking a
null pointer, casting it to an int, adding (I presume) another
int to it, and then trying to cast the result back to a pointer.
Moreover, unless I'm missing something, the int you're adding in
(that is, p->size) is fetched off of the null pointer you started
with. This doesn't look like it'll do anything useful, and it
*certainly* doesn't look like it'll allocate any memory!

I'm not sure I would have expected the compiler's first complaint
here to be about truncation of void * to int (in particular,
there aren't any void pointers in sight), but I'm glad it
complained about something, because you definitely need to
reexamine your thinking.

(There's an old rule, and it certainly applies here, that casts
should be used sparingly, and only when you know what you're
doing, and certainly not willy-nilly just to shut the compiler
up. In particular, you don't allocate memory by casting an int
to a pointer; you've got to call a memory-allocation function
somewhere! When the compiler complains about attempted
int-to-pointer conversions, and unless you're writing low-level
pointer manipulation code of the sort that only a linker ought to
be doing, the complaint almost invariably indicates that you're
mixing apples and oranges in an irreconciliable way, which the
insertion of a bunch of casts will only make worse.)

If the comment "Code to alloc mem etc" replaces some explicit
memory-allocation logic that is in your actual code; if p has
been appropriately set up to point at a SharedMemory::HEADER
object by the time you hit the line

p = (SharedMemory::HEADER *) ((int)p + p->size);

the problem may simply be that (int) cast, which is truncating a
pointer into an int (though the pointer it's truncating is a
SharedMemory::HEADER *, not a void *). What happens if you
remove both casts? That is, what happens if you use the
straightforward

p = p + p->size;

instead? That's normal-looking pointer arithmetic, and is
probably closer to what you want. The explicit casts make me
suspect that at some point you were either (a) trying to do the
pointer arithmetic in chunks of other than sizeof(SharedMemory::HEADER),
or (b) using void pointers which the compiler (correctly) wouldn't
let you do arithmetic on at all.

Steve Summit
sc*@eskimo.com
Nov 15 '05 #27

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

Similar topics

11
by: persevere | last post by:
#include <stdio.h> void main ( void ) { int *p, *q; p = q + 200; printf("%d %d %d %d", p, q, (int)p, (int)q); } The result is, "400 1439 0 1439".
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
4
by: Vijai Kalyan | last post by:
A very simple question. I have never had occasion to think about this before. Consider the following: class A { virtual unsigned long bar() { return reinterpret_cast<unsigned long> (this);
2
by: Magix | last post by:
Hi, I have following code. char buffer; void string_addchar(char *sourc, char ch) { int length; length=strlen(sourc);
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
2
by: david | last post by:
I've noticed that the following compiles (as C) under both VS8 and gcc with no warnings, even though there's a possibility of data truncation from enum to unsigned char. It does generate a warning...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.