Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: My C program does not compile or gives segmentation fault Date: Sun, 26 Mar 2017 02:35:49 -0700 Organization: None to speak of Lines: 20 Message-ID: References: <89549322-236e-4a59-9bb5-dc881593a846@googlegroups.com> <7e5f00ae-7843-42e8-9335-c46e1959244c@googlegroups.com> <1b1stnc1vj.fsf@pfeifferfamily.net> <1bshm3akop.fsf@pfeifferfamily.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="d1e16edf4d87c31e7fe6a303aaa5352a"; logging-data="18100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/T+U0P0SekXlOkGXI/viLw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:3fwIplyT5nI3Yco9ZAe7IWnq5sY= sha1:feLEQpdu3OXS+0JfA6ibb8/zxh0= Xref: csiph.com comp.lang.c:107095 Richard Heathfield writes: > On 24/03/17 17:48, David Brown wrote: >> And then you can safely cast your pointer if you want C++ compatibility >> - the risk of introducing a mistake here is very small. > > If you are calling malloc, you have already given up C++ compatibility, > because that isn't the C++ way of doing things. If you want a > dynamically allocated object or fixed size array, you use new, and if > you want a resizeable array you use std::vector. Or you use malloc, which is part of the C++ standard library. Valid reasons to write code that's valid both as C and as C++ are rare, but they're not nonexistent. -- 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"