chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] c-string return question


From: John Cowan
Subject: Re: [Chicken-users] c-string return question
Date: Thu, 13 Oct 2011 14:03:59 -0400
User-agent: Mutt/1.5.18 (2008-05-17)

Jörg F. Wittenberger scripsit:

> (Watch out for C_cblock and C_cblockend #defines in chicken.h , which
> depend on the C compiler in use.)

Normally, they are ({ and }) respectively, the
GNU C extension for statement expressions (see
http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html ). In C++ mode,
they compile as "do{" and "}while(0)" instead.  In neither case do they
do anything to the stack.

> It does a local #define return(x) to insert a block wherein it saves
> the to-be-returned string *before* the actual return statement is seen
> by the C compiler.

I looked at all instances of 'define return' and at most they seem to
copy pointers: they don't copy the chars that are pointed to.  That is
what matters here: one way or another, this code returns a pointer to
garbage outside the current stack.

> the trick as deployed in the Chicken source does not work under
> certain C compilers.

Since it's still not valid C despite the trick, that's no surprise.

An alternative approach to using a static string, overkill in this case,
is to malloc() the result string and declare the result type to be
c-string* rather than c-string.

-- 
Only do what only you can do.               John Cowan <address@hidden>
  --Edsger W. Dijkstra's advice
    to a student in search of a thesis



reply via email to

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