Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Auto-execute code at exit? Date: Mon, 11 Dec 2017 13:13:35 -0800 Organization: None to speak of Lines: 36 Message-ID: References: <016d6ddd-a7f6-498f-9fa0-244a5879bb9f@googlegroups.com> <0eb38248-278c-4f56-991f-e572a6b90fdf@googlegroups.com> <8zxXB.214638$9N.106141@fx30.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="669e685d4fbb910273bdaef1b49081a4"; logging-data="16101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YNj8UsRSRV6kw1BDH/feY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2PRBrT2CKya4QK5QP64ArIOf2Ew= sha1:92ciUtSJqaNdeiXPoi1Eyui5yjg= Xref: csiph.com comp.lang.c:124185 bartc writes: [...] > The real problem is that stdout etc are defined in a way that is not > conducive to their use from outside the language. Correct, standard C headers are designed to be used from C. Interoperability with other languages was not a major consideration in the design of the language. stdout is a macro, which means it can only be directly used by code that's been run through the C preprocessor and can use the resulting expansion (that usually means C, or C++, or Objective-C). You can study the C implementation's headers to reverse-engineer how stdout is defined, and use that information to write code in your own language that refers to the FILE* object that stdout refers to. The resulting solution will likely break when you try to use it with a different C implementation, or with a later version of the same C implementation. You can write a C function that returns the value of stdout and call that function from your language. (I presume your language has ways to do this.) In some cases, you can use a function that works with stdout implicitly, for example calling printf rather than fprintf. Of course this isn't a general solution. Or you can just complain at great length that C doesn't do something that you need, but that it was never designed to do. -- 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"