tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] C language modification using TinyCC - problems


From: Evan Langlois
Subject: Re: [Tinycc-devel] C language modification using TinyCC - problems
Date: Fri, 20 May 2005 15:08:29 -0500

> int main(int argc, char **argv) {
>       char    *s1 = "hi ";
>       char    *s2 = "neat!";
>       char    *s3 = "poo";
> 
>       printf("s1 %p\n", s1);
>       printf("s2 %p\n", s2);
>       printf("s3 %p\n", s3);
> 
>       s3 = s1 ~ s2;   // line 20
> 
>       printf("s1 %p\n", s1);
>       printf("s2 %p\n", s2);
>       printf("s3 %p\n", s3);
> 
>       return 0;
> }
> 
> My outputs are the following:
> 
> ex6.c:20: warning: assignment makes pointer from integer without a cast
> s1 0x807eb6c
> s2 0x807eb70
> s3 0x807eb76
> hi
> neat!

looks okay so far.

> hi neat!

Again, its fine.
> s1 0x807eb6c
> s2 0x807eb70
> s3 0xbffff5cc

Are you sure s3 is wrong?  Have you printed the string itself?
You aren't printing the value of the pointer "result" which is
over-writing the value of "s3".  Since result is malloc'd it makes sense
that the pointer (the new s3) might be very different from the
statically allocated strings.

The real problem I see is that you are implicitly allocating storage
that must be explicitly deallocated.  This "extension" might introduce
extra allocation errors and more places to keep track of pointers.  Of
course, if you can get boehms-gc to link with tcc generated code, then
you are all set.  Contrary to popular belief, I've found that garbage
collected programs can often run FASTER than either explicit memory
management and even faster than calling malloc() and never free()ing the
storage!

> What am I doing wrong?  s3's value looks wrong and produces the same
> garbage string each time the program runs.  As you can see, __concat

Your test program doesn't show the garbage string.

> is getting the parameters correct and successfully concatenates them. 
> The generated code, however, does not process the return type
> correctly.  I hope it's a small, easy fix!  =)

Maybe stack corruption?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]