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 17:09:16 -0700 Organization: None to speak of Lines: 54 Message-ID: References: <5608591F.8020005@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="22865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T7Yu68ZCUdgeD5a/oYJYU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:pv9VIdvWgQkyr4A2DJbDWndxQpE= sha1:zNdtoZGoTB+EkdLlHsq+PiHPPqE= Xref: csiph.com comp.lang.c:71322 "Morten W. Petersen" writes: [...] > A bit awkward perhaps, but this works: > > #include > > #define my_func_SIGNATURE int my_func(int a, int b) > > my_func_SIGNATURE; > > __inline__ my_func_SIGNATURE { > return a+b; > } > > int main() { > int a = 1; > int b = 2; > printf("Result of a+b: %i\n", my_func(a,b)); > } This works and is not awkward: #include int my_func(int a, int b); inline int my_func(int a, int b) { return a+b; } int main(void) { int a = 1; int b = 2; printf("Result of a+b: %i\n", my_func(a,b)); } (You could just omit the separate declaration in this case, but it's useful, or even required, in more complicated code.) I changed your "int main()" to "int main(void)" because the latter is more correct (that's a very minor point). "__inline__" is a non-standard gcc extension. Just use "inline" unless you need to cater to pre-C99 compilers. Your "my_func_SIGNATURE" just makes your code more difficult to read. Every time I see it, I have to track down its definition to understand what it means. -- 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"