From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,1f8050edb14e8329 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!feeder.eternal-september.org!eternal-september.org!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Interfacing to C Date: Fri, 01 Jan 2010 10:02:01 -0800 Organization: None to speak of Message-ID: References: <56284e56-6ac5-427c-8e4f-8a0750527088@z41g2000yqz.googlegroups.com> <53faf11a-df58-45ca-b287-5e1901fcf5a4@c34g2000yqn.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 1 Jan 2010 18:04:57 +0000 (UTC) Injection-Info: news.motzarella.org; posting-host="9Q3eM4Wnxd9DPQClR7vYpA"; logging-data="27186"; posting-account="U2FsdGVkX1/c25owVzSNuuVmgcmz0FGx" User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:/+l06MCb9f9qRY7PzCiE6Uel8gI= sha1:plpGDQE5I4eCXieLXwm0VGznW38= Xref: g2news1.google.com comp.lang.ada:8573 Date: 2010-01-01T10:02:01-08:00 List-Id: Robert A Duff writes: > Keith Thompson writes: [...] >> Yes. In fact, C doesn't have pass by reference as a language feature; >> *all* function arguments are passed by value. >> >> For structs, it's very common in C to do the equivalent of >> pass-by-reference, by explicitly passing the address of the struct >> object. This is partly because very old versions of C didn't >> support struct parameters. > > Which version of C (when?) introduced (by-copy) struct params? It appeared in the 1989 ANSI C standard. It was undoubtedly implemented in some compilers a few years before that. K&R1 (Kernighan & Ritchie, "The C Programming Language, 1st edition, 1978) had structs, but didn't allow them to be assigned or passed as arguments. To be clear, C has *never* allowed structs to be passed by reference implicitly, though it's always allowed the equivalent by explicit coding. >> I find it a bit odd that Ada imposes a pass-by-pointer convention for >> C structs. > > It was a mistake. Partly my fault. I was thinking that it's common in > C to pass struct params by explicitly passing a pointer-to-struct, so > Ada should mimic that. Bad idea. By the time we realized the mistake, > it was too late to fix (compatibility!), so we invented C_Pass_By_Copy > as a workaround. > >> (No, C arrays aren't passed by reference. C array expressions, in >> most contexts, are implicitly converted to pointers; the resulting >> pointer can be passed by value.) > > Yeah. In other words, C arrays aren't passed, period. > That's another bad idea, and it's not my fault. ;-) Right, C arrays are very much second-class citizens, almost always manipulated indirectly via pointers. (There's a common misconception that C arrays and pointers are the same thing. They most definitely are not. See section 6 of the comp.lang.c FAQ, , for the details.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"