[mC dsPIC 4.0.0.0] wrong pointer calculation

Discuss about beta versions of mikroC compiler.
Post Reply
Author
Message
bruno
Posts: 767
Joined: 10 Sep 2005 02:10
Location: Lyon, France
Contact:

[mC dsPIC 4.0.0.0] wrong pointer calculation

#1 Post by bruno » 07 Apr 2008 00:35

Hello,

can you please consider this piece of code (dsPIC30F6014) :

Code: Select all

        dir = (DIRENT *)sect ;
UART1_print("PTR:") ;
printFix(bufOut, dir, 1000000) ;
UART1_printVar(bufOut) ;
UART1_print("\r") ;
        memcpy(dir->nameExt, ".          ", 11) ;
        dir->attrib = 0x10 ;
        dir->first[0] = cl & 0xff ;
        dir->first[1] = cl >> 8 ;

//        dir = (DIRENT *)(sect + DIRENT_SIZE) ;
        dir += DIRENT_SIZE ;
UART1_print("DIRENT_SIZE:") ;
printFix(bufOut, DIRENT_SIZE, 1000000) ;
UART1_printVar(bufOut) ;
UART1_print("\r") ;
UART1_print("PTR:") ;
printFix(bufOut, dir, 1000000) ;
UART1_printVar(bufOut) ;
UART1_print("\r") ;
sect is defined as pointer to an unsigned char buffer
dir is defined as pointer to a DIRENT struct

at run time I get :
PTR:006162
DIRENT_SIZE:000032
PTR:007186
but 6162 + 32 != 7186 should be 6194 :!:

watching asm :

Code: Select all

;commands.c,404 :: 		dir += DIRENT_SIZE ;
$1988	$204004			MOV	#1024, W4
$198A	$90104E			MOV	[W14+40], W0
$198C	$420810			ADD	W4, [W0], [W0]
1024 is added to pointer, instead of 32 :shock:

if I use tagged pointer affectation instead of pointer calculation all is going well.

where does 1024 come from :?:

Thank you !
Bruno
Bored with 7-segment ? Try the [url=http://www.micro-examples.com/public/microex-navig/doc/079-touchclock.html]TouchClock[/url]

Post Reply

Return to “mikroC Beta testing”