VOGONS


First post, by deimond

User metadata
Rank Newbie
Rank
Newbie

hi,

I'm a newbie in c and dosbox.
What i want to do is to initialize on adress lets say 0x2b0 a 1 byte value 0x00. How and where i can do that in the simplest way?
What i want is the program who read a byte from adress 0x2b0 get the static value defined in code.

Reply 1 of 1, by ripa

User metadata
Rank Oldbie
Rank
Oldbie
char* address = 0xA0000;
*address = 0x55; // write 0x55 to 0xA0000
printf("contents of %p is %x\n", address, *address); // read from 0xA0000

You can verify this with Valgrind (since the address I used was unallocated):

==10002== Invalid write of size 1
==10002== at 0x400589: main (in /secret/path)
==10002== Address 0xa0000 is not stack'd, malloc'd or (recently) free'd

edit: Added reading example.

edit2: Better answers here. You might need to use "volatile".