Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #142676
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C Translator |
| Date | 2019-04-01 11:33 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <q7slsc$mpm$1@dont-email.me> (permalink) |
| References | (17 earlier) <dW4oE.682614$ao.267556@fx32.am4> <q7r3rg$ua7$1@dont-email.me> <lZ8oE.867468$iV1.117974@fx25.am4> <871s2m9140.fsf@bsb.me.uk> <jfboE.1537594$Xct1.1147500@fx12.am4> |
On 01/04/2019 00:33, Bart wrote:
> On 31/03/2019 22:37, Ben Bacarisse wrote:
>> Bart <bc@freeuk.com> writes:
>
>>> programs of my examples,
>
> I meant a complete source file such as is submitted to a C compiler.
>
>> static int fred(void); int main(void) {}
>
>> should compile and none requires a diagnostic.
>
> So, a source file can have any number of forward, static function
> declarations (and each can be repeated any number of times). But none
> needs to be actually defined, provided it is not referenced? Ok...
Yes, that's right.
Again, that kind of flexibility can be convenient, and can make the
language simpler to specify. But it also means that you can't make
assumptions that a static declaration is always matched with a definition.
Flexibility has its advantages and disadvantages. But remember, C was
designed primarily for the people who write C programs - not for people
who write C tools. Any difficulties there might be in writing C
compilers were of minor concern - and any difficulties in automatically
translating C to other languages would have been irrelevant.
>
>> int fred(void); int main(void) { return fred(); }
>>
>> Undefined. A function is used but there is no definition of it. fred
>> has external linkage (I don't know if that is local, exported or
>> imported -- you could tell me).
>
> Really?
>
> Let me give you a hint: if I was running a business and buying goods
> from overseas, I would be importing. If I was producing goods to sell
> overseas, then I'd be exporting.
I think we all know what the words "import" and "export" mean. We also
all know how C works. But what we /don't/ know, is how /you/ think C
works, and why you think C should have ways to say exactly what /you/
think it should say, or why you think C should not allow people to say
things /you/ think it should not allow.
C is not "Bart's own language". You don't get to make the rules. You
can't expect other languages to fit the rules you like in your
languages. You can dislike the C rules if you want - but only if you
understand them enough to give a qualified opinion (this is often not
the case). I don't know of anyone in this group, myself included, who
like all the rules of C. But we understand the need to learn them,
understand them, and work with them.
>
> The same with functions in a source file; either they're defined here
> and marked static (local), or defined here without static (exported), or
> declared here but defined elsewhere (imported).
>
> Or it might be that I'm just being wound up because I can't believe a
> programmer cannot be aware of what 'importing' and 'exporting' a
> function might mean inside a source file.
You are wound up because C does not fit your simplistic rules - and
other people understand that, while you don't. C does not have a
concept of "import" and "export" - it has a concept of "internal
linkage" and "external linkage" (and also "no linkage"). These don't
match "import" and "export". They can be used to provide something
equivalent to "import" and "export, but they are not limited to that.
(I personally prefer my code to make clean divisions between "import",
"export", and "local to the file". But that is how I choose to use C,
not how C is limited.)
>
> Or, it could really be (as nothing about this language surprises me any
> more), that for C, 'external linkage' is all that is needed. Shared
> functions are just considered to be floating around unattached to any
> particular source file.
>
That is, in fact, closer to the truth.
>
> That certainly appears to be the case with variables, in that ownership
> of a variable is not fully established until link-time. You can't
> determine it purely from one source file.
I've explained this already. Why do you ask questions, if you have no
intention of reading the answers?
>
> Which means a translation from one C source file at a time into another
> language is impossible, if the target language demands that a shared
> variable must be classed as either imported or exported.
I don't expect it to be impossible, but I expect it to be rather
difficult unless you restrict the C you accept, or duplicate the effects
of it.
But why is that a surprise? Why would you expect to be able to
translate one language completely and directly to another language? C
was designed to be compiled to assembly - it was not designed to be
translated into arbitrary other languages. No programming language is
designed for that.
>
> It seems C leaves that open, even if technically it doesn't. Since one
> of my tests had one file initialising 'abc' to 0 via 6.9.2p2, and
> another initialising it explicitly, yet all C compilers (except mine)
> compiled without comment:
>
> -----------------------
> c.c
> -----------------------
> #include <stdio.h>
>
> int abc;
>
> int main(void){
> printf("%d\n",abc);
> }
> -----------------------
> d.c
> -----------------------
> int abc=7788;
> -----------------------
>
> Transcript:
>
> C:\c>gcc -std=c11 c.c d.c
>
> C:\c>a
> 7788
>
Credit where credit is due - I am happy to see a reference to the C
standard. I think this is a first for you!
However, you have failed to read or understand the explanation I gave in
another post. It seems pointless to repeat here.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C Translator Bart <bc@freeuk.com> - 2019-03-28 16:16 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 00:01 +0000
Re: C Translator Robert Wessel <robertwessel2@yahoo.com> - 2019-03-28 20:31 -0500
Re: C Translator Keith Thompson <kst-u@mib.org> - 2019-03-28 19:02 -0700
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 02:34 +0000
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-03-29 10:58 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 12:47 +0000
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-03-29 14:57 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 14:57 +0000
Re: C Translator fir <profesor.fir@gmail.com> - 2019-03-29 15:08 -0700
Re: C Translator fir <profesor.fir@gmail.com> - 2019-03-29 15:42 -0700
Re: C Translator scott@slp53.sl.home (Scott Lurndal) - 2019-03-29 15:16 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 15:30 +0000
Re: C Translator fir <profesor.fir@gmail.com> - 2019-03-29 14:47 -0700
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-29 10:42 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 11:57 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 13:04 +0000
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-03-29 14:58 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 14:29 +0000
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-29 20:06 +0000
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-29 20:02 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-29 21:10 +0000
Re: C Translator nobody@example.org (Scott) - 2019-03-30 04:52 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-30 11:03 +0000
Re: C Translator nobody@example.org (Scott) - 2019-03-30 16:17 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-30 18:36 +0000
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-30 20:32 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-30 22:44 +0000
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-31 03:23 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-31 12:39 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-31 15:07 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-31 16:21 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-03-31 21:19 +0200
Re: C Translator Bart <bc@freeuk.com> - 2019-03-31 20:58 +0100
Re: C Translator Ike Naar <ike@iceland.freeshell.org> - 2019-03-31 20:33 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-03-31 22:06 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-31 22:37 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-31 23:33 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-01 02:35 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-01 11:33 +0200
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-03-31 23:54 +0200
Re: C Translator Bart <bc@freeuk.com> - 2019-04-01 02:16 +0100
Re: C Translator Ike Naar <ike@iceland.freeshell.org> - 2019-04-01 06:42 +0000
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-01 11:35 +0200
Re: C Translator Bart <bc@freeuk.com> - 2019-04-01 16:54 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-04-01 21:01 +0100
Re: C Translator Keith Thompson <kst-u@mib.org> - 2019-04-01 13:41 -0700
Re: C Translator Bart <bc@freeuk.com> - 2019-04-01 22:40 +0100
Re: C Translator Keith Thompson <kst-u@mib.org> - 2019-04-01 16:25 -0700
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-02 00:50 +0100
Re: C Translator Keith Thompson <kst-u@mib.org> - 2019-04-01 17:45 -0700
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-02 11:28 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 13:18 +0200
Re: C Translator Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-04-02 19:15 +0000
Re: C Translator Bart <bc@freeuk.com> - 2019-04-02 21:14 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-02 13:28 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 10:49 +0200
Re: C Translator Bart <bc@freeuk.com> - 2019-04-02 01:58 +0100
Re: C Translator Keith Thompson <kst-u@mib.org> - 2019-04-01 19:13 -0700
Re: C Translator Bart <bc@freeuk.com> - 2019-04-02 11:13 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 13:49 +0200
Re: C Translator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-04-02 05:15 -0700
Re: C Translator Bart <bc@freeuk.com> - 2019-04-02 14:50 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 16:06 +0200
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 16:05 +0200
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-02 00:11 +0100
Re: C Translator David Brown <david.brown@hesbynett.no> - 2019-04-02 10:35 +0200
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-02 00:06 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-31 21:36 +0100
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-31 16:32 +0100
Re: C Translator Bart <bc@freeuk.com> - 2019-03-30 00:37 +0000
Re: C Translator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-03-30 01:00 +0000
Re: C Translator fir <profesor.fir@gmail.com> - 2019-03-30 03:37 -0700
Re: C Translator fir <profesor.fir@gmail.com> - 2019-03-30 06:15 -0700
Re: C Translator James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-29 07:49 -0700
csiph-web