Re: Division in loop

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Randi Botse wrote:

> Thanks Glynn for let me know that the void* pointer arithmetic is
> undefined, and gcc automatically cast it to char* pointer... is this
> because void* doesn't have a size?

Technically, it's because the standard says that it's undefined.

Pointer arithmetic is defined in terms of pointers to array elements,
e.g. if you have:

	int foo[N];
	int *p = &foo[A];
	int *q = p+B;
	int *r = &foo[A+B];

then r==q. But you can't have an array of "void", so pointer
arithmetic on void* isn't meaningful.

> im curious when i do sizeof(void*),
> my machine tell me sizeof(void*) is 4kb... i thnk when i do (void* +
> 1) that's means "4 kb after void*"?....

The result of sizeof is in bytes (technically, "char"s; sizeof(char)
is guaranteed to be 1).

The result of "sizeof" applied to any pointer type will typically be 4
bytes on 32-bit systems or 8 bytes on 64-bit systems. Although it's
possible for pointers to different types to have different sizes, it's
rare.

> i run the code in GNOME terminal, that's means stdout connected to xterm?

No, to Gnome terminal; xterm is similar.

It's possible that the behaviour which you experience is a property of
the terminal emulator. You might try running the program on a
different terminal emulator, or on a VT, to see if the same problem
occurs there.

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.