Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Unexpected and difficult to understand SIGSEGV Date: Sun, 27 Sep 2015 15:54:44 -0700 Organization: None to speak of Lines: 37 Message-ID: References: <5608591F.8020005@verizon.net> <56086BB4.6000508@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="10483"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19s1Cs1pk5XrlxWaAayoSf5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:pRm6khGhEp15+bQ4dMG7rurTjVI= sha1:utLQPlhbwBy4SA+F2AxPYevPInQ= Xref: csiph.com comp.lang.c:71310 James Kuyper writes: [...] > Because you're making the mistake of insisting on using C90, you've > enabled the "implicit int" rule that caused so much trouble that it was > removed in C99. As a result, if you use a function in test.c without > first declaring it, the compiler acts as though a implicit declaration > was provided that takes the specified number of arguments, and returns > an int value. If the parameters of your functions have types compatible > with the promoted types of the corresponding arguments, and the return > value is in fact 'int' - or if the return value isn't used, then the > behavior of your code is well defined. Even if the return value isn't > 'int', if it's the same size as 'int', on many platforms your code will > still appear to work - which is bad for you, because you've missed an > opportunity to detect a code defect. [...] If the return type isn't int, you'll have undefined behavior even if the result isn't used. For example: double func(void) { return 0.0) } /* * In another source file where no declaration of func() is visible: */ func(); In C90, the call is not a constraint violation, but the behavior is undefined, because the type of the function is not compatible with the type of the prefix expression. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"