char *vidmem=(char *)0xb8000

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

is this the only way to reference a specific memory address?
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

also why does it work when u assign the address of a variable(an integer) to a pointer?

char *pntr;
pntr=&varint;
Whatever5k

Re:char *vidmem=(char *)0xb8000

Post 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.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

works in c++....gpp
Tim

Re:char *vidmem=(char *)0xb8000

Post by Tim »

That's probably because you've got warnings turned off. Add -Wall to the command line.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:char *vidmem=(char *)0xb8000

Post 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!
Every good solution is obvious once you've found it.
Tim

Re:char *vidmem=(char *)0xb8000

Post 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).
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

does anyone know of a programming language that allows the programmer to explictily assign a certain memory address to a pointer?
Tim

Re:char *vidmem=(char *)0xb8000

Post by Tim »

Yes, C. Use a type cast.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

i mean a programming language where you can say:

pointer=0xb8000;

with using a "hack" or anything like that
Tim

Re:char *vidmem=(char *)0xb8000

Post 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?"
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

what languages were ms-dos,windows 95, win98,win2k,winxp written in?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:char *vidmem=(char *)0xb8000

Post 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".
Every good solution is obvious once you've found it.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

shouldnt there be something that complys with the ISO standard that allows it to reference a memory address?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:char *vidmem=(char *)0xb8000

Post 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?!?
Every good solution is obvious once you've found it.
Post Reply