Line comments versus line splicing [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Wed 2013-06-19 14:02
Line comments versus line splicing
LinkReply
[personal profile] simontWed 2013-06-19 15:18
To my way of thinking, the least mind-bending option is to say that escaping has unequivocally higher precedence than any syntax that uses newlines: either you see the escape token at the end of a line, or the newline isn't escaped.

I think this is precisely where pragmatism and conceptual simplicity diverge: the option you describe leads directly to the ASCII art trap, which it seems to me is a severe violation of the Principle of Least Astonishment (especially in C/C++'s strict implementation where invisible trailing whitespace can change the meaning) and imparts a fair amount of mindbendingness to my way of thinking.

your point that the syntax of preprocessor directives in C/C++ is an obvious misfeature in the first place. (If they could be freely interpolated, life would be much better in many ways [...])

That's a considerably broader point than the one I'd intended to make, but I'll cheerfully subscribe to it regardless. Being able to embed macro definitions anywhere, including in the expansions of other macros, would certainly offer scope for some exciting perversions :-)

Though that makes comment-to-nl itself feel like a mistake in the language

It is odd, now I think about it, that neither of C/C++'s comment syntaxes nests properly. If they were going to throw in a second comment syntax, they could have had it fix the bug in the first one!

you don't make explicit what you want this to do: [...] I'm guessing you want it to treat ten.o and eleven.o as being on the same line?

Yes, that was my intention. (I thought I had made that explicit, though perhaps I left an unintended loophole in the wording. The line containing ten.o has a line-splicing backslash by rule 1, and therefore rule 3 applies to the line following it.)

Rule 3 is a curveball, I agree, but then I was approaching the entire problem from a use-cases perspective to see what would happen, and since the conceptually clean approaches in C/C++ and shell both turn out to lead to weird use cases, it didn't surprise me that my use-case-focused reanalysis led to weird concepts :-)

a far neater solution is to set aside a dedicated character, not used for anything else, and say that character to end of line is whitespace

Hmm, yes, that is quite neat; a sort of comment-to-just-after-nl as opposed to (or rather, offered as an alternative to) the more usual comment-to-just-before-nl.
Link Reply to this | Parent | Thread
[personal profile] gerald_duckWed 2013-06-19 16:31
The perversion of defining a macro in the expansion of another macro is orthogonal to the issue of whether or not preprocessor directives can be freely interpolated. The C/C++'s preprocessor could have allowed:
  #define MOO(define) #define x QUACK

…but they've prohibited it from working the way you might expect (and hijacked # inside macros for another purpose, which is why I was sick and used "define" as the macro parameter's name (-8 ).

I'm guessing they decided that macros defining macros was a can of worms best left unopened.

At this point I'm remembering Modula-3's pragma syntax: <**> to go with the Wirth (**) for comments. (How come everyone's happy using [] for arrays in Pascal instead of (..), but still uses (**) instead of {} for comments?) Had C used something similar, we could have avoided all this __attribute__ and __declspec nonsense for starters!

If I ever design a language in the C problem space, knowing what I know now, the pragma syntax will be something like:

void f() {
  #pragma #switch(COMPILER_VERSION) {
      RECENT_GCC:
          diagnostic push;
          diagnostic ignored "-Wuninitialized";
          break;
      MSVC:
          warning(push);
          warning(disable: C4700);
          break;
  }

  // Do some stuff...

  #pragma #switch(COMPILER_VERSION) {
      RECENT_GCC: diagnostic pop; break;
      MSVC: warning(pop); break;
  }
}
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]