File: args_default.inc

package info (click to toggle)
critcl 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,680 kB
  • sloc: ansic: 41,058; tcl: 12,090; sh: 7,230; pascal: 3,456; asm: 3,058; ada: 1,681; cpp: 1,001; cs: 879; makefile: 333; perl: 104; xml: 95; f90: 10
file content (39 lines) | stat: -rw-r--r-- 1,234 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[comment {-*- mode: tcl ; fill-column: 90 -*-}]

[list_begin enumerated]

[enum] Reread the example of the main section. Note specifically the line [example {
    int {level ZSTD_CLEVEL_DEFAULT}
}]

[enum] This line demonstrates that [cmd critcl::cproc] arguments allowed to have default
values, in the same vein as [cmd proc] arguments, and using the same syntax.

[enum] [emph Attention] Default values have to be legal C rvalues and match the C type of
the argument.

[para] They are literally pasted into the generated C code.

[para] They bypass any argument validation done in the generated translation layer. This
means that it is possible to use a value an invoker of the command cannot use from Tcl.

[enum] This kind of in-band signaling of a default versus a regular argument is however
not necessary.

[para] Look at [example {
    critcl::cproc default_or_not {int {x 0}} void {
	if !has_x {
	    printf("called with default\n");
	    return
	}
	printf("called with %d\n", x);
    }
}]

[para] Any argument [arg x] with a default causes [vset critcl] to create a hidden
argument [arg has_x], of type int (boolean).

This argument is set to [const 1] when [arg x] was filled from defaults, and [const 0]
else.

[list_end]