Page 2 of 3
Re:char *vidmem=(char *)0xb8000
Posted: Sat Jul 05, 2003 7:08 am
by slacker
is this the only way to reference a specific memory address?
Re:char *vidmem=(char *)0xb8000
Posted: Sat Jul 05, 2003 10:34 am
by slacker
also why does it work when u assign the address of a variable(an integer) to a pointer?
char *pntr;
pntr=&varint;
Re:char *vidmem=(char *)0xb8000
Posted: Sat Jul 05, 2003 10:37 am
by Whatever5k
GCC gives me a warning here, as it should be. Same situation here: ptr is a pointer to char and var is an integer, so you're getting a warning.
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 7:14 am
by slacker
works in c++....gpp
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 7:41 am
by Tim
That's probably because you've got warnings turned off. Add -Wall to the command line.
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 11:12 am
by Solar
slacker wrote:
also why does it work when u assign the address of a variable(an integer) to a pointer?
char *pntr;
pntr=&varint;
Because gcc sometimes lets utterly illegal code pass through...
The address of a variable is a
pointer, not an
integer. While both
happen to be of the same size on most machines, that is by no means to be taken for granted.
int i;
ptr p;
sizeof(i) and sizeof(p) are identical on
most machines, yet still they are utterly
different types.
i = 42;
p = i; // illegal code, generates warning!
p = &i; // p does
not contain 42!
And always rule #1: Just because a certain compiler doesn't complain about a certain piece of code, that doesn't mean that piece of code is legal!
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 4:18 pm
by Tim
I wouldn't even say "most". Machines that spring to mind are 16-bit x86 (pointers are 16 bits or 32 bits, ints are 16 bits, longs are 32 bits) and IA64 (pointers are 64 bits, ints and longs are 32 bits).
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 4:21 pm
by slacker
does anyone know of a programming language that allows the programmer to explictily assign a certain memory address to a pointer?
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 4:23 pm
by Tim
Yes, C. Use a type cast.
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 4:33 pm
by slacker
i mean a programming language where you can say:
pointer=0xb8000;
with using a "hack" or anything like that
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 5:20 pm
by Tim
By "hack", I mean "code which isn't compliant with the ISO C Standard". You're breaking the C Standard by merely writing an operating system; a little typecast on a pointer isn't going to hurt anything.
The compiler's error message on your first piece of code is its way of saying, "Hey! This code might not work! You'd better take a look at it. By the way, you know it's not going to run on any other machines, don't you?"
Re:char *vidmem=(char *)0xb8000
Posted: Sun Jul 06, 2003 6:11 pm
by slacker
what languages were ms-dos,windows 95, win98,win2k,winxp written in?
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 12:52 am
by Solar
Assembler, C, C++, plus parts in VisualBasic I'd daresay.
Come on, slacker. Do you listen to what is said? All that's required from you is making it explicit you want 0xb8000 to be an address (instead of an integer).
Explicitness isn't a "hack".
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 7:38 am
by slacker
shouldnt there be something that complys with the ISO standard that allows it to reference a memory address?
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:05 am
by Solar
Try:
(char*) 0xb8000.
From "ISO C Syntax",
http://eic.sourceforge.net/iso_c.html:
Code: Select all
unary-expr:
postfix-expr
++ unary-expr
-- unary-expr
unary-operator cast-expr
sizeof unary-expr
sizeof ( type-name )
unary-operator: one of
& * + - ~ !
cast-expr:
unary-expr
( type-name ) cast-expr
multiplicative-expr:
cast-expr
multiplicative-expr * cast-expr
multiplicative-expr / cast-expr
multiplicative-expr % cast-expr
Really, slacker, you're making a fuzz over perfectly legal code.
0xb8000 is an integer number.
(char*) 0xb8000 is a pointer to a character at address 0xb8000.
(int*) 0xb8000 is a pointer to an integer at address 0xb8000.
char* vidmem = 0xb8000 is assigning an integer to a pointer type, which isn't 100% OK and thus generates a warning.
char* vidmem = (int*) 0xb8000 isn't 100% OK either and thus will also generate a warning.
char* vidmem = (char*) 0xb8000 is assigning a char pointer to a char pointer - OK, no warning.
I really don't understand what's your problem here?!?