Pointer and binary issues

Programming, for all ages and all languages.
Post Reply
pacman
Posts: 17
Joined: Sun Jul 08, 2007 10:23 am

Pointer and binary issues

Post by pacman »

Hi

Im getting really annoying messages from DJGPP (gcc) concerning the following code:

Code: Select all

unsigned int *pageTable;
pageTable = virtualBlock.startingEntry.pageDirectory[i];
pageTable = pageTable & 0xFFFFF000;
GCC keeps throwing:

Code: Select all

error: invalid operands to binary &
Also, for this code...

Code: Select all

     void *returnAddress = (void *) virtualBlock.startingEntry.pageDirectoryEntry * 1024 * 4096;
I get...

Code: Select all

error: invalid operands to binary *
What am I doing wrong?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

You are attempting normal maths with pointers - try casting the pointers to integers before attempting the binary operations (you will, of course need to cast back to a pointer for the assignment back to the pointer variable).

Cheers,
Adam
zerosum
Member
Member
Posts: 63
Joined: Wed Apr 09, 2008 6:57 pm

Post by zerosum »

I might point out that your paging structures need to be page-aligned anyway. If they were, doing a bitwise AND with 0xFFFFF000 would have no effect at all, since the least significant 12 bits would already be zero. If they're not [page-aligned], then you're going to have problems when you try to load them into cr3.

Cheers,
Lee
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post by Korona »

I guess they are page aligned and the op wants to get rid of the flags by doing a binary and operation.
Post Reply