char *vidmem=(char *)0xb8000
Re:char *vidmem=(char *)0xb8000
is this the only way to reference a specific memory address?
Re:char *vidmem=(char *)0xb8000
also why does it work when u assign the address of a variable(an integer) to a pointer?
char *pntr;
pntr=&varint;
char *pntr;
pntr=&varint;
Re:char *vidmem=(char *)0xb8000
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
That's probably because you've got warnings turned off. Add -Wall to the command line.
Re:char *vidmem=(char *)0xb8000
Because gcc sometimes lets utterly illegal code pass through...slacker wrote: also why does it work when u assign the address of a variable(an integer) to a pointer?
char *pntr;
pntr=&varint;
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!
Every good solution is obvious once you've found it.
Re:char *vidmem=(char *)0xb8000
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
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
i mean a programming language where you can say:
pointer=0xb8000;
with using a "hack" or anything like that
pointer=0xb8000;
with using a "hack" or anything like that
Re:char *vidmem=(char *)0xb8000
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?"
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
what languages were ms-dos,windows 95, win98,win2k,winxp written in?
Re:char *vidmem=(char *)0xb8000
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".
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".
Every good solution is obvious once you've found it.
Re:char *vidmem=(char *)0xb8000
shouldnt there be something that complys with the ISO standard that allows it to reference a memory address?
Re:char *vidmem=(char *)0xb8000
Try:
(char*) 0xb8000.
From "ISO C Syntax", http://eic.sourceforge.net/iso_c.html:
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?!?
(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
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?!?
Every good solution is obvious once you've found it.