Re: Keil c51 interprets &Array as Array. Is that normal?



On Thu, 10 Apr 2008 14:59:03 +0100, Bill Davy wrote:

If I compile:

void Foo(void)
{
{ char Array[10]; char *p; p = &Array; }// Silly { char Array[10]; char
*p; p = Array; } // Better { char Array[10]; char *p; p = &Array[0];
}// Some find this clearer
}

I get:

; .\Foo.SRC generated from: Foo.c
; COMPILER INVOKED BY:
; C:\Keil\C51\BIN\C51.EXE Foo.c LARGE OMF2 BROWSE
INCDIR(H:\Husky\HostPC\V1\) DEBUG TABS(3) SRC(.\Foo.SRC)


NAME FOO

?PR?Foo?FOO SEGMENT CODE
?XD?Foo?FOO SEGMENT XDATA OVERLAYABLE
PUBLIC Foo

RSEG ?XD?Foo?FOO
?Foo?BYTE:
Array?040: DS 10
ORG 10
p?041: DS 3
ORG 0
Array?042: DS 10
ORG 10
p?043: DS 3
ORG 0
Array?044: DS 10
ORG 10
p?045: DS 3
; void Foo(void)

RSEG ?PR?Foo?FOO
Foo:
USING 0
; SOURCE LINE # 1
; {
; SOURCE LINE # 2
; { char Array[10]; char *p; p = &Array; }// Silly
; SOURCE LINE # 3
MOV DPTR,#p?041
MOV A,#01H
MOVX @DPTR,A
INC DPTR
MOV A,#HIGH (Array?040)
MOVX @DPTR,A
INC DPTR
MOV A,#LOW (Array?040)
MOVX @DPTR,A
; { char Array[10]; char *p; p = Array; } // Better
; SOURCE LINE # 4
MOV R1,A
MOV DPTR,#p?043
MOV A,#01H
MOVX @DPTR,A
INC DPTR
MOV A,#HIGH (Array?042)
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
; { char Array[10]; char *p; p = &Array[0]; }// Some find this clearer
; SOURCE LINE # 5
MOV DPTR,#p?045
MOV A,#01H
MOVX @DPTR,A
INC DPTR
MOV A,#HIGH (Array?044)
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
; } ; SOURCE LINE # 6
RET
; END OF Foo

END

-------------------

IDE-Version:
Vision3 V3.60
Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2008

Tool Version Numbers:
Toolchain: PK51 Prof. Developers Kit Version: 8.12 Toolchain
Path: C:\Keil\C51\BIN\
C Compiler: C51.Exe V8.12

-----------------

Is this normal?
MSVC 6 issues a warning (C4047).

'Array' should cast seamlessly to 'pointer to char'; &Array should cast
to 'pointer to pointer to char'.

Are you sure that Kiel does it so that &Array == Array? I can't see how
Array is an lvalue here, if it isn't it'd be hard to take it's address.

--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
.



Relevant Pages