Difference between revisions of "Template:Csig"

From Maths
Jump to: navigation, search
m (Adding case of 3 present but empty to show brackets (for functions with no arguments))
m (Adding template:ctd - for typedefs)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{cs|1={{{1|<noinclude>int</noinclude>}}} {{{2|<noinclude>printf</noinclude>}}}<!--
+
{{cs|1={{#if:{{{pre|}}}|{{{pre|}}} <nowiki/>|}}{{echo|1={{{1|<noinclude>int</noinclude>}}}}} {{echo|1={{{2|<noinclude>printf</noinclude>}}}}}<!--
  
 
-->{{#if:{{{3|<noinclude>const char*</noinclude>}}}{{{4|<noinclude>format</noinclude>}}}<!--
 
-->{{#if:{{{3|<noinclude>const char*</noinclude>}}}{{{4|<noinclude>format</noinclude>}}}<!--
Line 8: Line 8:
 
case true:
 
case true:
 
     if 3 concatenated with 4 is not empty (ie there is an arg)
 
     if 3 concatenated with 4 is not empty (ie there is an arg)
     -->({{csig/Arg|1={{{3|}}}|2={{{4|}}}|3={{csig/Arg|1={{{5|}}}|2={{{6|}}}|3=<!--END-->}}}})<!--
+
        ARGUMENTS ARE EXPANDED HERE
 +
     -->(<!--
 +
ARG1
 +
-->{{csig/Arg|1={{{3|}}}|2={{{4|}}}|3=<!--
 +
ARG2
 +
-->{{csig/Arg|1={{{5|}}}|2={{{6|}}}|3=<!--
 +
ARG3
 +
-->{{csig/Arg|1={{{7|}}}|2={{{8|}}}|3=<!--
 +
ARG4
 +
-->{{csig/Arg|1={{{9|}}}|2={{{10|}}}|3=<!--
 +
ARG5
 +
-->{{csig/Arg|1={{{11|}}}|2={{{12|}}}|3=<!--
 +
ARG6
 +
-->{{csig/Arg|1={{{13|}}}|2={{{14|}}}|3=<!--
 +
Closing arg6
 +
-->}}<!--
 +
Closing arg5
 +
-->}}<!--
 +
Closing arg4
 +
-->}}<!--
 +
Closing arg3
 +
-->}}<!--
 +
Closing arg2
 +
-->}}<!--
 +
closing arg3
 +
-->}}<!--
 +
closing bracket
 +
-->)<!--
  
 
     -->|<!--
 
     -->|<!--
Line 21: Line 48:
 
--> {{{post|}}}<!--
 
--> {{{post|}}}<!--
  
-->}}
+
-->}}<noinclude>
 +
==Usage==
 +
Currently supports up to 6 arguments, you may use {{C|pre}} and {{C|post}} to make things appear before and after (with a space between them and the body, if present), arguments go as follows:
 +
# return or type (eg {{C|int}})
 +
# symbol name (eg {{C|printf}})
 +
# arg1 - type (eg {{C|const char*}})
 +
#* If not present, then no brackets are rendered after the symbol name, for a variable definition
 +
#* If present but empty then brackets are shown, this is how you'd achieve a function with no arguments over a variable
 +
# arg1 - name
 +
# arg2 - type
 +
# arg2 - name
 +
# arg3 - type
 +
# arg4 - name
 +
and so on.
 +
 
 +
An argument is considered present if the type/name arguments are ''not both empty'', so an empty type with the name as {{C|...}} is valid, for example varadic functions (c-style)
 +
==[[/Example|Examples]]==
 +
{{/Example}}
 +
==Family==
 +
Think of any {{C|*_t}} versions as "template" - to be used alone, without the {{C|_t}} at the end they may be styling (only csig and cs are designed to be used alone and lack a {{C|_t}} to indicate this)
 +
* [[template:cprim]] - used within [[template:csig]] or [[template:cs]] to style primitive types.
 +
** [[template:cprim_t]] - standalone version, used inline, rather than inside csig or cs
 +
* [[template:ckw]] - used within csig or cs
 +
** [[template:ckw_t]] - standalone version
 +
* [[template:ctd]] - typedefs
 +
** [[template:ctd_t]] - standalone version
 +
 
 +
</noinclude>

Latest revision as of 08:40, 1 October 2017

int printf()

Usage

Currently supports up to 6 arguments, you may use pre and post to make things appear before and after (with a space between them and the body, if present), arguments go as follows:

  1. return or type (eg int)
  2. symbol name (eg printf)
  3. arg1 - type (eg const char*)
    • If not present, then no brackets are rendered after the symbol name, for a variable definition
    • If present but empty then brackets are shown, this is how you'd achieve a function with no arguments over a variable
  4. arg1 - name
  5. arg2 - type
  6. arg2 - name
  7. arg3 - type
  8. arg4 - name

and so on.

An argument is considered present if the type/name arguments are not both empty, so an empty type with the name as ... is valid, for example varadic functions (c-style)

Examples

  • int printf(const char* format, ...)
  • int printf(const char* format, ...)
  • int errno __attribute__((aligned(16)))
  • pid_t getpid()
  • long:
    • int lots_of_args(a b, c d, e f, g h) __attribute__((noreturn))

Family

Think of any *_t versions as "template" - to be used alone, without the _t at the end they may be styling (only csig and cs are designed to be used alone and lack a _t to indicate this)