[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++)
From: |
Bob Paddock |
Subject: |
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++) |
Date: |
Wed, 07 Mar 2007 09:24:25 -0500 |
User-agent: |
Opera Mail/9.10 (Win32) |
On Tue, 06 Mar 2007 23:12:16 -0500, Dmitry K. <address@hidden>
wrote:
On Wednesday 07 March 2007 13:18, Eric Weddington wrote:
Are you use non-pure avr-gcc 4.1.1 ?
Below is from the stock WinAVR-20070122 edition,
compiled for the CAN64.
Going back to your original code,
I had to add a empty foo() to get it to compile
at all. I used the standard mfile generated
Makefile.
void foo (const char *s1, const char *s2);
void foo (const char *s1, const char *s2)
{
}
int main( void );
int main( void )
{
unsigned char c1, c2;
char s1[2] = ".";
char s2[2] = ".";
for (c1 = 1; c1; c1++) {
for (c2 = 1; c2; c2++) {
s1[0] = c1;
s2[0] = c2;
foo (s1, s2);
}
}
return 0;
}
Yes, I do not see an error in yours code.
But there is a bit of differences:
- main() is started with pushing r16,17,28,29 into stack
- stack pointer is not loaded to SP ports, it is modifyed
All of this is absent in my disassembler result.
And can somebody to compile this example?
4.1.1 main.lss:
void foo (const char *s1, const char *s2);
void foo (const char *s1, const char *s2)
{
ce: 08 95 ret
000000d0 <main>:
}
int main( void );
int main( void )
{
d0: 80 e0 ldi r24, 0x00 ; 0
d2: 90 e0 ldi r25, 0x00 ; 0
d4: 08 95 ret
Other than the standard stuff, like .do_copy_data_loop
et.al., that is all I get. No closing brace, it just
stops! I've seen this with some 'real' code as well,
long before the end of a function was reached.
Actual .hex file, that matches above code:
:100000000C944A000C9465000C9465000C946500F7
:100010000C9465000C9465000C9465000C946500CC
:100020000C9465000C9465000C9465000C946500BC
:100030000C9465000C9465000C9465000C946500AC
:100040000C9465000C9465000C9465000C9465009C
:100050000C9465000C9465000C9465000C9465008C
:100060000C9465000C9465000C9465000C9465007C
:100070000C9465000C9465000C9465000C9465006C
:100080000C9465000C9465000C9465000C9465005C
:100090000C94650011241FBECFEFD0E1DEBFCDBFB1
:1000A00011E0A0E0B1E0E6EDF0E002C005900D92B5
:1000B000A030B107D9F711E0A0E0B1E001C01D9276
:1000C000A030B107E1F70C9468000C94000008958B
:0600D00080E090E00895BD
:00000001FF
With 3.4.5 this is what I get, same Makefile, same code:
void foo (const char *s1, const char *s2);
void foo (const char *s1, const char *s2)
{
ce: 08 95 ret
000000d0 <main>:
}
int main( void );
int main( void )
{
d0: cf ef ldi r28, 0xFF ; 255
d2: d0 e1 ldi r29, 0x10 ; 16
d4: de bf out 0x3e, r29 ; 62
d6: cd bf out 0x3d, r28 ; 61
unsigned char c1, c2;
char s1[2] = ".";
char s2[2] = ".";
for (c1 = 1; c1; c1++) {
d8: 91 e0 ldi r25, 0x01 ; 1
for (c2 = 1; c2; c2++) {
da: 81 e0 ldi r24, 0x01 ; 1
dc: 8f 5f subi r24, 0xFF ; 255
de: f1 f7 brne .-4 ; 0xdc <main+0xc>
e0: 9f 5f subi r25, 0xFF ; 255
e2: d9 f7 brne .-10 ; 0xda <main+0xa>
s1[0] = c1;
s2[0] = c2;
foo (s1, s2);
}
}
return 0;
}
e4: 80 e0 ldi r24, 0x00 ; 0
e6: 90 e0 ldi r25, 0x00 ; 0
e8: 0c 94 76 00 jmp 0xec <_exit>
000000ec <_exit>:
ec: ff cf rjmp .-2 ; 0xec <_exit>
Try adding these compiler directives one at a time,
and see what comes out. -Wall does *NOT* actually
"enable all warnings", some below are covered by -Wall,
some are not:
# -pedantic : Issue all the mandatory diagnostics listed in the C
# standard. Some of them are left out by default, since they trigger
frequently
# on harmless code.
#
# -pedantic-errors : Issue all the mandatory diagnostics, and make all
# mandatory diagnostics into errors. This includes mandatory diagnostics
that
# GCC issues without -pedantic but treats as warnings.
#CFLAGS += -pedantic
# Warn if a requested optimization pass is disabled.
# This warning does not generally indicate that there
# is anything wrong with your code; it merely indicates that
# GCC's optimizers were unable to handle the code effectively.
# Often, the problem is that your code is too big or too complex;
# GCC will refuse to optimize programs when the optimization itself
# is likely to take inordinate amounts of time.
#CFLAGS += -Wdisabled-optimization
# Warn if the loop cannot be optimized because the compiler could
# not assume anything on the bounds of the loop indices.
#CFLAGS += -Wunsafe-loop-optimizations
# Warn about uninitialized variables which are initialized with themselves.
# Note this option can only be used with the -Wuninitialized option,
# which in turn only works with -O1 and above. [What about -Os??]
# (C, C++, Objective-C and Objective-C++ only)
#CFLAGS += -Winit-self
# Warn whenever a function parameter is unused aside from its declaration.
#CFLAGS += -Wunused-parameter
# Warn if the compiler detects that code will never be executed.
# [Seems to give bogus results at times.]
#CFLAGS += -Wunreachable-code
# Warn if an undefined identifier is evaluated in an `#if' directive.
#CFLAGS += -Wundef
It is my personal opinion that something is broken in 4.1.1,
but I have not been able to come up with a simple test
case to show it. I have 'real' code that
runs in 3.4.5, but does not in 4.1.1, for a old project.
As I need CAN64 support staying with 3.4.5
is not really an option for my latest project.
How painful would it be for me to build
3.4.5/6 with CAN64 support on Windows?
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++), Shaun Jackman, 2007/03/07