[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] c-string return question
From: |
Alan Post |
Subject: |
Re: [Chicken-users] c-string return question |
Date: |
Thu, 13 Oct 2011 11:34:32 -0600 |
On Thu, Oct 13, 2011 at 07:24:12PM +0200, Jörg F. Wittenberger wrote:
> IMHO the moral of the story: Never trust you C compiler too much.
>
I've had to get more familiar with gcc's -f flag, as the years have
gone by. '-fno-strict-aliasing' is one that I've personally needed
(and chicken requires too, I believe) for some time now, and
variously I've had to turn those on and off based on writing C that
was a little too comfortable with the underlying machine
architecture.
A favorite trick of mine, for instance:
struct string {
size_t string_size;
char string_buffer[1]; /* note the single character string */
}
Where I then malloc 'sizeof(struct string)+strlen(str)' all as one
block of memory and write the string past the end of the struct.[1]
You might find a wonderful playground of debugging potential if you
try this code fiddling with your -f options: start with the ones
that get defined with -O3, particularly those that aren't defined
in -O2.
-Alan
1: this stores both the size of the string and an extra character
for the null pointer, which I do on purpose.
--
.i ma'a lo bradi cu penmi gi'e du
- Re: [Chicken-users] c-string return question, (continued)
- Re: [Chicken-users] c-string return question, Jim Ursetto, 2011/10/13
- Re: [Chicken-users] c-string return question, Jörg F . Wittenberger, 2011/10/13
- Re: [Chicken-users] c-string return question, John Cowan, 2011/10/13
- Re: [Chicken-users] c-string return question, Alan Post, 2011/10/13
- Re: [Chicken-users] c-string return question, John Cowan, 2011/10/13
- Re: [Chicken-users] c-string return question, Alan Post, 2011/10/13
- Re: [Chicken-users] c-string return question, Jörg F . Wittenberger, 2011/10/13
- Re: [Chicken-users] c-string return question, Jörg F . Wittenberger, 2011/10/13
- Re: [Chicken-users] c-string return question, Jörg F . Wittenberger, 2011/10/13
Re: [Chicken-users] c-string return question, Jörg F . Wittenberger, 2011/10/13
- Re: [Chicken-users] c-string return question,
Alan Post <=