All of lore.kernel.org
 help / color / mirror / Atom feed
From: Riley Williams <rhw@InfraDead.Org>
To: Robert de Bath <robert$@mayday.cix.co.uk>
Cc: Manuel Novoa III <mjn3@codepoet.org>,
	Linux-8086 <linux-8086@vger.kernel.org>
Subject: Re: C compiler, assembler and linker
Date: Tue, 23 Jul 2002 01:34:21 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.21.0207230104510.4272-100000@Consulate.UFP.CX> (raw)
In-Reply-To: <1c289c8ad98ba628@mayday.cix.co.uk>

Hi Robert, Manuel.

>> 1) #elif support.

> Okay, reasonable.

I haven't had a chance to look at this yet, so this comment is probably
irrelevant, but...does this support handle the following correctly?

	#define MODE1
	#define MODE3

	#ifdef MODE1
	#  ifdef DEBUG
	#    define DBGMODE 1
	#  endif
	#elifdef MODE2
	#  define DBGMODE 2
	#elifdef MODE3
	#  define DBGMODE 3
	#else
	#  define DBGMODE 4
	#endif

	#ifndef DBGMODE
	#  define DBGMODE 0
	#endif

With at least one C compiler I've used over the years, DBGMODE ended up
with the value 3 rather than the value 1 that it should have in that case.

>> 2) #warning support (at least for non-continued lines).

> Hmm, a bit primitive, but, wth, It'll do the job.

>> 3) Support asm() at file scope.  This is to allow the equivalent
>>    of #asm/#endasm in macros.

> Hmm, interesting, I'll have to look at this ... carefully.

>> 4) Limited support for things like "#define stdio stdio". Stock bcc
>>    goes into an infinite loop when encounting this. The implementation
>>    has flaws, but it does what I needed. You see this a lot in the
>>    glibc headers we're using with uClibc (yes I'm working on a port).

One obvious optimisation is this: Where a #define has the same value for
its value as its name, the entire #define is treated as a comment. That
would deal with the above define, but could have problems with...

	#define stdio (stdio)

...which probably also fails with the old system.

> I don't like the way this is done; I think it'd be better to
> 'smudge' the definition of the current macro so that the search
> can't find the word for recursion.

When are macros expanded? If they are expanded as they are met in the
code, the above can't cause a problem as the macro isn't defined until
after the value has been expanded. However, if the preprocessor reaps
all the macros and then expands them in a separate pass, recursion
problems are inevitable.

As an example of this, how is the following code handled?

	int main()
	{
		int VALUE = 7;

	#define VALUE 12

		printf("Test 1 = %d\n", VALUE );

	#undef VALUE

		printf("Test 2 = %d\n", VALUE );
		exit(0);
	}

Whilst not good coding, that code is perfectly valid K&R C but any
compiler that first reaps the #define/#undef statements and expands the
macros in a separate pass can produce faulty code in two different ways,
and can fail to compile in two other ways...

Best wishes from Riley.


  reply	other threads:[~2002-07-23  0:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-14 14:05 C compiler, assembler and linker Harry Kalogirou
2002-07-14 17:27 ` Manuel Novoa III
2002-07-15  6:07   ` Riley Williams
2002-07-15 17:02     ` Manuel Novoa III
2002-07-15 19:13       ` Riley Williams
2002-07-15 22:02         ` Manuel Novoa III
2002-07-16  6:27           ` Riley Williams
2002-07-17  1:31             ` Manuel Novoa III
2002-07-17  6:33               ` Riley Williams
2002-07-18 12:03                 ` Minix vs. ELKS Feher Tamas
2002-07-18 12:27                   ` Javier Sedano
2002-07-02 15:07                     ` (unknown) Miguel A. Bolanos
2002-07-18 13:40                   ` Minix vs. ELKS Alan Cox
2002-07-22 21:41                 ` C compiler, assembler and linker Robert de Bath
2002-07-23  8:16               ` Robert de Bath
2002-07-23 16:25                 ` Manuel Novoa III
2002-07-23 19:09                   ` Robert de Bath
2002-07-24 21:17         ` More dev86 changes (0.16.5) Robert de Bath
2002-07-24 22:02           ` Riley Williams
2002-07-25 15:42             ` Manuel Novoa III
2002-07-26  7:55               ` Robert de Bath
2002-07-26 15:12                 ` Manuel Novoa III
2002-07-26  8:22             ` Robert de Bath
2002-07-24 22:26           ` Paul Nasrat
2002-07-25 16:34             ` Manuel Novoa III
2002-07-22 23:26       ` C compiler, assembler and linker Robert de Bath
2002-07-23  0:34         ` Riley Williams [this message]
2002-07-23  0:58           ` Manuel Novoa III
2002-07-23  0:46         ` Manuel Novoa III
2002-07-15 14:16 Ken Martwick
2002-07-15 19:21 ` Riley Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0207230104510.4272-100000@Consulate.UFP.CX \
    --to=rhw@infradead.org \
    --cc=Riley@Williams.Name \
    --cc=linux-8086@vger.kernel.org \
    --cc=mjn3@codepoet.org \
    --cc=robert$@mayday.cix.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.