5

I was looking at google go's runtime source code (at https://go.googlecode.com/hg/src/pkg/runtime/ ), and it seems they use a special character for their function names, · . (Look for example at https://go.googlecode.com/hg/src/pkg/runtime/cgocall.c ). Is this accepted across major compilers? It's not ANSI C, is it? Or is it just some macro magic?

Thank you!

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Waneck
  • 2,450
  • 1
  • 19
  • 31
  • By looking at the example, I just realized that the symbol appears only between runtime and some other name (`runtime·cgocall`, `runtime·throw`, `runtime·allm`). – pmg Dec 19 '11 at 16:23
  • @pmg: It's used as a namespace identifier, which I think is very clever, very cool and very inconvenient to use. – Niklas B. Dec 19 '11 at 16:25
  • 2
    Hmm, this *does* appear to be quite a clever way of simulating namespaces in ANSI C. Hopefully the answers explore what might be any caveats to doing so, rather than just telling you what the character is. – Cody Gray - on strike Dec 19 '11 at 16:26
  • @CodyGray Yeah that's what I think. It's really clean :) – Waneck Dec 19 '11 at 16:29
  • it's really clean... for C code generators :) – Waneck Dec 19 '11 at 16:46

4 Answers4

5

C90 doesn't allow additional character in identifier (over those in the basic characters set), C99 do (both with the universal character syntax -- \uXXXX and \UXXXXXXXX -- and an implementation defined set of other characters).

6.4.2.1/1 in C99:

identifier:
    identifier-nondigit
    identifier identifier-nondigit
    identifier digit
identifier-nondigit:
    nondigit
    universal-character-name
    other implementation-defined characters
nondigit: one of
    _ a b c d e f g h i j k l m
    n o p q r s t u v w x y z
    A B C D E F G H I J K L M
    N O P Q R S T U V W X Y Z
digit: one of
    0 1 2 3 4 5 6 7 8 9

I don't know how well it is supported by C implementations, I know that Plan9 C compiler could handle other characters before it was standardized.

AProgrammer
  • 51,233
  • 8
  • 91
  • 143
2

Do you mean the dot? It's character code 183 from ISO 8859-1 (ISO Latin-1) - it's an extended ASCII code corresponding (apparently) to the Georgian comma, aka "middle dot". It is actually a legal character.

Thomas
  • 3,321
  • 1
  • 21
  • 44
1

The C99 Standard "allows" (for sufficiently small values of "allow") 'strange characters'

5.1.1.2 Translation phases

1 The precedence among the syntax rules of translation is specified by the following phases.

  1. Physical source file multibyte characters are mapped, in an implementation defined manner, to the source character set (introducing new-line characters for end-of-line indicators) if necessary. Trigraph sequences are replaced by corresponding single-character internal representations.
pmg
  • 106,608
  • 13
  • 126
  • 198
1

Using that middle dot is discussed here:

http://code.google.com/p/go/issues/detail?id=793

Basically, using that dot is not part of the spec, but there are some cases where it is necessary. Bootstrapping, runtime, or assembly.

Derek
  • 3,087
  • 1
  • 21
  • 23
  • I don't understand. How/why is it necessary for bootstrapping the system? Are you talking about the Go language, perhaps, rather than the C code linked to by the question? – Cody Gray - on strike Dec 19 '11 at 16:34
  • I think this issue relates to google go's identifiers, not C identifiers. That's why they must be talking about bootstrapping the compiler. – Waneck Dec 19 '11 at 16:45
  • The way I understand it is that since there already exist functions that use the middle dot, Go needs to make calls to those functions using that middle dot in cgocall.c in order to call out. – Derek Dec 19 '11 at 16:53