> On Mon, 10 Jan 2011 08:52:56 +0000, Seebs wrote:
>> On 2011-01-10, arnuld <> wrote:
> I am starting to wonder whether you should just give up on C.
I won't
>> struct myStruct
>> {
>> char title[10];
>> };
>
>> int main(void)
>> {
>> struct myStruct *st;
>
>> strcpy(st->title, "clc");
> What does st point to?
>
> If this two-line bug doesn't leap out at you, after the number of times
> you've gone through this, maybe this is not the right language for you.
>
> It's one thing not to understand this stuff when you've never seen it
> before, but you've had MANY questions which involved uninitialized
> pointers, and any compiler I've used in the last decade or two would
> have warned you about this if you had it configured sanely.
gcc -ansi -pedantic -Wall -Wextra does not give any warning:
[arnuld@dune downloads]$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-4

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
I think I missed out the bug probably because my brain was engaged
somewhere else, I am trying to solve an issue of Segmentation Fault in
some code (which I can't post as its proprietary). There is a linked list
of such kind of struct pointers and a for loop is going on it. NULL != st-
>title passes through but '\0' == st->title[0] gives a Segfault in some
very rare situations. Don't know why its happening but unlike this 2 line
example that code does have a malloc() with a null check. My brain was
totally into that when I wrote this example.
--
http://www.lispmachine.wordpress.com