Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #142663

Re: C Translator

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: C Translator
Date 2019-03-31 22:37 +0100
Organization A noiseless patient Spider
Message-ID <871s2m9140.fsf@bsb.me.uk> (permalink)
References (15 earlier) <jG1oE.282641$kh.152691@fx27.am4> <877ecf9lyv.fsf@bsb.me.uk> <dW4oE.682614$ao.267556@fx32.am4> <q7r3rg$ua7$1@dont-email.me> <lZ8oE.867468$iV1.117974@fx25.am4>

Show all headers | View raw


Bart <bc@freeuk.com> writes:

> With input of:
>
>     static int fred(void);
>
> ... all C compilers pass it with no warnings

That's correct.  A function need only be defined if it is used.

> (using default options in all cases)

Please stop doing this.  At least ask for the code to be treated as C
(e.g. -std=c11 for gcc) rather than whatever language the compiler is
pushing.

> and treat it as an import. Is my translator wrong, or those compilers?

That I don't know, because (and I know you probably won't believe me), I
don't know what "treat it as an import" means.  I say a bit more about
that later on.

> With input of:
>
>     int abc;
>
> my translator gives output of:
>
>     global int32 abc
>
> (ie. assumes it is exported.). However, 'int abc;' is commonly used in
> C programs to declare that 'abc' is imported from elsewhere. This
> generally gets sorted out in a linker (which either fixes the problem,
> or reports a multiple definition).

This again!  I should assume you don't remember.  If you did, you would
explain what is going on, yes?

> I assume you're quite good at this stuff. So in each of these complete
> programs of my examples, is fred or abc local, exported or imported,
> or is there a bug in the program, or is there a bug in every C
> compiler I tried:
>
>     int fred(void);
>
>     static int fred(void);
>
>     int abc;

I think there are some typos in the question, but as I read it, if each
line is taken as a complete program, they are all undefined.  The
compiler can do anything it likes because there is no main function.
With a null main, all of these

  int fred(void); int main(void) {}

  static int fred(void); int main(void) {}

  int abc; int main(void) {}

should compile and none requires a diagnostic.  Since the named entities
are not used, the implementation can ignore them, but in so far as it
makes any sense to say so in a complete program, the two 'fred's and
'abc' have external, internal and external linkage respectively.

Adding a main that uses the declared entities we can say more:

  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).

  static int fred(void); int main(void) { return fred(); }

Also undefined, but fred has internal linkage this time.

  int abc; int main(void) { return abc; }

Fine.  The program returns 0 (a "successful termination status") to the
host environment.  abc has external linkage, though it makes no
difference since this is a complete program.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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