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: To include or not to include Date: Tue, 27 Sep 2016 09:30:46 -0700 Organization: None to speak of Lines: 26 Message-ID: References: <87zimyhk54.fsf@bsb.me.uk> <87a8ewgb5y.fsf@bsb.me.uk> <87r388dzw9.fsf@bsb.me.uk> <87vaxhbhhi.fsf@bsb.me.uk> <87inthbf8o.fsf@bsb.me.uk> <9b8d8341-12b3-4f11-9bc4-4d4e712d2b00@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="23050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ts1wA7A03u4ezZB3ivky2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:yAq/Hyy/GL3lr/r60WxT7ehQ3eo= sha1:u6QmPEZ9uALY8jNzOxY4ALqGi7Q= Xref: csiph.com comp.lang.c:94154 Malcolm McLean writes: > On Tuesday, September 27, 2016 at 3:16:01 PM UTC+1, Ben Bacarisse wrote: [...] >> No, it's a problem with the language. A modern language would have >> name-spaces and/or a module mechanism. >> > It's also a problem with the way C linkers and compilers usually work. > Let's say I need to duplicate a string in several areas. One way is to > declare mystrdup() a global function. But I'm writing a dungeon > generator module, I don't want to export trivial string handling > functions. So the best option is to make mystrdup() static, and drop a > copy in dungeongeneratormk1.c, dungeongeneratormk2.c and so on. No, the best option is to define mystrdup() in one place and make it visible in other translation units. But if you insist on making it static, you can always define it in a .c file and #include that .c file where you need it. You'll have multiple definitions in your program, but only one definition in your source code. -- 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"