~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty-proposed

« back to all changes in this revision

Viewing changes to yo/classes/existingtypes.yo

  • Committer: Package Import Robot
  • Author(s): Frank B. Brokken
  • Date: 2013-05-30 13:32:18 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20130530133218-k39mr5uredd093jr
Tags: 9.7.2-1
New upstream release, repairs several minor left-over flaws.
This release incorporates 9.7.0 and 9.7.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Once a type name has been defined it also prevails over identifiers
 
2
representing variables, if the compiler is given a choice. This, too, can
 
3
result in interesting constructions.
 
4
 
 
5
Assume a function tt(process) expecting an tt(int) exists in a library. We
 
6
want to use this function to process some tt(int) data values. So in tt(main)
 
7
tt(process) is declared and called:
 
8
        verb(
 
9
    int process(int Data);
 
10
    process(argc);
 
11
        )
 
12
    No problems here. But unfortunately we once decided to `beautify' our
 
13
code, by throwing in some superfluous parentheses, like so:
 
14
        verb(
 
15
    int process(int (Data));
 
16
    process(argc);
 
17
        )
 
18
    Now we're in trouble. The compiler now generates an error, caused by its
 
19
rule to let declarations prevail over definitions. tt(Data) now becomes the
 
20
name of the tt(class Data), and analogous to tt(int (x)) the parameter tt(int
 
21
(Data)) is parsed as tt(int (*)(Data)): a pointer to a function, expecting a
 
22
tt(Data) object, returning an tt(int). 
 
23
 
 
24
Here is another example. When, instead of declaring 
 
25
        verb(
 
26
    int process(int Data[10]);
 
27
        )
 
28
we declare, e.g., to emphasize the fact that an array is passed to
 
29
tt(process):
 
30
        verb(
 
31
    int process(int (Data[10]));
 
32
        )
 
33
    the tt(process) function does not expect a pointer to tt(int) values, but
 
34
a pointer to a function expecting a pointer to tt(Data) elements, returning an
 
35
tt(int). 
 
36
 
 
37
To summarize the findings in the `Ambiguity Resolution' section:
 
38
    itemization(
 
39
    it() The compiler will try to remove superfluous parentheses;
 
40
    it() But if the parenthesized construction represents a type, it will try
 
41
        to use the type;
 
42
    it() More in general: when possible the compiler will interpret a
 
43
        syntactic construction as a declaration, rather than as a definition
 
44
        (of an object or variable).
 
45
    )