API Reference


with-c-syntax is a fun package which introduces the C language syntax into Common Lisp.


The with-c-syntax package, holding public APIs.
  • Macro WITH-C-SYNTAX ((&rest options &key (keyword-case (common-lisp:readtable-case common-lisp:*readtable*)) (case-sensitive (common-lisp:ecase with-c-syntax.core::keyword-case ((:upcase :downcase) common-lisp:nil) ((:preserve :invert) common-lisp:t))) (return :auto) (try-add-{} common-lisp:t)) &environment *wcs-expanding-environment* &body body)
    This macro is a entry point of the with-c-syntax system. BODY will be interpreted as C syntax, executed, and return values. CASE-SENSITIVE specifies case-sensitivity in interpreting symbols. If nil, C syntactic keyworks and Libc functions are treated case-insentisively. KEYWORD-CASE is used for calculating CASE-SENSITIVE parameter. If RETURN is `:auto', returns the last form's value if BODY is a compound statement. (If BODY is a compilation unit, this returns NIL now, but this behavior may be changed.) If RETURN is any other value, its valus is inserted after the compilation result translation units. (This feature is intended to access 'static' variables.) ?f TRY-ADD-{} is t and an error occurred at parsing, `with-c-syntax' adds '{' and '}' into the head and tail of FORM respectively, and tries to parse again.
    Holds the reader level used by '#{' reader function. The value is one of 0, 1, 2, or nil (default). The default is nil, recognized same as `+with-c-syntax-default-reader-level+'. For inside '#{' and '}#', three syntaxes are defined. These syntaxes are selected by the infix parameter of the '#{' dispatching macro character. If it not specified, its default is this value. Available syntaxes are below: * Level 0 (conservative) In level 0, these reader macros are installed. - ',' :: ',' is read as a symbol. (In ANSI CL, a comma is defined as an invalid char outside the backquote syntax.) - ':' :: Reads a solely ':' as a symbol. Not a solely one (as a package marker) works as is. Level 0 is almost comatible with the standard syntax. However, we need many escapes using C symbols. * Level 1 (aggressive). In level 1, these reader macros are installed. - '{', '}', '[', ']' :: These become a terminating character, and read as a symbol. - '`' :: '`' reads a next s-exp in the previous syntax. This works as an escape from '#{' and '}#' The 'backquote' functionality is lost. - '.' :: Reads a solely '.' as a symbol. The 'consing dot' functionality is lost. - '' :: The '' becomes a ordinary constituent character. The 'multiple escaping' functionality is lost. - '/' :: '//' means a line comment, '/* ... */' means a block comment. '/' is still non-terminating, and has special meanings only if followed by '/' or '*'. Ex: 'a/b/c' or '/+aaa+/' are still valid symbols. - ''' (single-quote) :: The single-quote works as a character literal of C. The 'quote' functionality is lost. - '"' (double-quote) :: The double-quote works as a string literal of C. Especially, escaping is treated as C. The original functionality is lost. - ';' :: ';' becomes a terminating character, and read as a symbol. The 'comment' functionality is lost. - '(' and ')' :: parenthesis become a terminating character, and read as a symbol. The 'reading a list' functionality is lost. Level 1 overwrites macro characters in the standard syntax. Only constituent characters are left unchanged. Especially, '(' and ')' loses its functionalities. For constructing a list of Lisp, the '`' syntax must be used. * Level 2 (overkill) In this level, these characters become terminating, and read as a symbol listed below. - '?' :: '?' - '~' :: '~' - ':' :: ':' - '.' :: '.' - '=' :: '=' or '==' - '*' :: '*' or '*=' - '^' :: '^' or '^=' - '!' :: '!' or '!=' - '&' :: '&', '&&', or '&=' - '|' :: '|', '||', or '|=' - '+' :: '+', '++', or '+=' - '-' :: '-', '--', '-=', or '->' - '>' :: '>', '>>', or '>>=' - '<' :: '<', '<<', or '<<=' - '/' :: '/', or '/='. '//' means a line comment, and '/* ... */' means a block comment. In this level, there is no compatibilities between symbols of Common Lisp. Especially, for denoting a symbol has terminating characters, escapes are required. (ex. most-positive-fixnum)
    Holds the reader case used by '#{' reader function. When this is not nil, it must be one of `:upcase', `:downcase', `:preserve', or `:invert'. The specified case is used as the readtable-case inside '#{' and '}#' and passed to the wrapping `with-c-syntax' form. When this is nil, it is used as the readtable-case of `*readtable*' at '#{'.


Holds symbols denoting C operators and keywords.
No exported symbols.


with-c-syntax core package.
    * Class Precedence List with-c-syntax-error, simple-error, ... * Description The type ~with-c-syntax-error~ consists of all errors in with-c-syntax system.
    * Class Precedence List with-c-syntax-warning, simple-warning, ... * Description The type ~with-c-syntax-warning~ consists of all warnings in the with-c-syntax system.
  • Function FIND-STRUCT-SPEC (name)
    * Syntax ~find-struct-spec~ name => struct-spec * Arguments and Values - name :: a symbol - decl-spec :: a struct-spec instance, or nil. * Description Finds and returns a struct-spec. If no struct-specs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Function ADD-STRUCT-SPEC (name sspec)
    * Syntax ~add-struct-spec~ name sspec => struct-spec * Arguments and Values - name :: a symbol. - sspec :: a struct-spec instance. - struct-spec :: a struct-spec instance. * Description Establishes a new struct-spec definition named ~name~. * Affected By ~with-c-compilation-unit~.
  • Function REMOVE-STRUCT-SPEC (name)
    * Syntax ~remove-struct-spec~ name => struct-spec * Arguments and Values - name :: a symbol - struct-spec :: a struct-specs instance, or nil. * Description Removes a struct-spec definition named ~name~. Returns the removed struct-spec definition. If no struct-specs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Class STRUCT
    * Class Precedence List struct, standard-object, ... * Description A representation of C structs or unions.
  • Function MAKE-STRUCT (spec-obj &rest init-args)
    * Syntax ~make-struct~ spec-obj &rest init-args => new-struct * Arguments and Values - spec-obj :: a symbol, or an instance of struct-spec. - init-args :: objects. - new-struct :: an instance of struct. * Description Makes a new struct instance based on the specification of ~spec-obj~. If ~spec-obj~ is a symbol, it must be a name of a globally defined struct or union. To define a struct or an union globally, use ~with-c-syntax~ and declare it in a toplevel of translation-unit. If ~spec-obj~ is an instance of struct-spec, it is used directly. ~init-args~ is used for initializing members of the newly created instance. If the number of ~init-args~ is less than the number of members, the rest members are initialized with the default values specified by the ~spec-obj~.
  • Function STRUCT-MEMBER (struct member-name)
    * Syntax ~struct-member~ struct member-name => object * Arguments and Values - struct :: an instance of struct - member-name :: a symbol - object :: an object * Description Returns the value of the member named ~member-name~ in the ~struct~.
  • Function (setf STRUCT-MEMBER) (val struct member-name)
    * Syntax (setf (~struct-member~ struct member-name) new-object) * Arguments and Values - struct :: an instance of struct - member-name :: a symbol - new-object :: an object * Description Sets the value of the member named ~member-name~ in the ~struct~.
  • Function FIND-TYPEDEF (name)
    * Syntax ~find-typedef~ name => decl-spec * Arguments and Values - name :: a symbol - decl-spec :: a decl-specs instance, or nil. * Description Finds and returns a typedef definition. If no typedefs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Function ADD-TYPEDEF (name spec)
    * Syntax ~add-typedef~ name spec => decl-spec * Arguments and Values - name :: a symbol - spec :: a decl-specs instance, or a type specifier. - decl-spec :: a decl-specs instance. * Description Establishes a new typedef definition named ~name~. * Affected By ~with-c-compilation-unit~.
  • Function REMOVE-TYPEDEF (name)
    * Syntax ~remove-typedef~ name => decl-spec * Arguments and Values - name :: a symbol - decl-spec :: a decl-specs instance, or nil. * Description Removes a typedef definition named ~name~. Returns the removed typedef definition. If no typedefs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Type PSEUDO-POINTER (&optional (pointee-type t))
    The base type of internal representation of null and non-null pointers in with-c-syntax sysrem.
  • Macro WITH-PSEUDO-POINTER-SCOPE (nil &body body)
    In this macro, BODY is executed in a new environment for pseudo-pointers. A pointer made inside this macro is invalidated outside of this.
    This function invalidates all pseudo-pointers in the scope it called, and returns the number of invalidates pointers. In `with-pseudo-pointer-scope', this call invalidates pseudo-pointers made in that. If out of that, this call invalidates all pseudo-pointers.
  • Function PSEUDO-POINTER-POINTABLE-P (object)
    Returns whether the OBJECT can be held by pseudo-pointers.
  • Function MAKE-PSEUDO-POINTER (pointee &optional (initial-offset 0))
    Makes and returns a new pseudo-pointer points POINTEE. INITIAL-OFFSET is added to the result at making.
    Dereferences the POINTER and returns the pointed object.
  • Function (setf PSEUDO-POINTER-DEREFERENCE) (new-object pointer)
    Makes the POINTER to point the NEW-OBJECT.
  • Function PSEUDO-POINTER-INVALIDATE (pointer)
    Makes the POINTER to point no objects. After that, calling `pseudo-pointer-dereference' to this pointer will be error.
  • Function BUILD-LIBC-SYMBOL-CACHE (&optional (package (find-package '#:with-c-syntax.libc)))
    Build a cache used by `intern-libc-symbol'
  • Function BUILD-LIBC-SYMBOL-CACHE (&optional (package (find-package '#:with-c-syntax.libc)))
    Build a cache used by `intern-libc-symbol'
  • Function FIND-PREPROCESSOR-MACRO (symbol)
    Finds and returns a preprocessor macro definition named SYMBOL, added by `add-preprocessor-macro'.
  • Function ADD-PREPROCESSOR-MACRO (symbol value)
    Establishes a new preprocessor macro to SYMBOL, which is corresponded to VALUE. Preprocessor macros are held in `symbol-plist' of SYMBOL, and indicated by `+preprocessor-macro+'.
    Removes a preprocessor macro named SYMBOL.
  • Macro DEFINE-PREPROCESSOR-CONSTANT (name value &environment env)
    Defines a new preprocessor symbol macro, named by NAME and its value is VALUE.
  • Macro DEFINE-PREPROCESSOR-FUNCTION (name lambda-list &body body)
    Defined a new preprocessor function, named by NAME.
  • Function PREPROCESSOR (lis case-sensitive)
    This function preprocesses LIS before parsing. Current workings are below: - Interning a symbol into this package when it has a same name as C keywords or operators, or libc symbols. - Concatenation of string literals. - Calling preprocessor macros, defined by `add-preprocessor-macro'. How preprocessor macros are expanded is described below. - A dirty hack for 'typedef'. Automatically adds 'void ;' after each typedef declarations. This is a workaround for avoiding the problem between 'the lexer hack' and the look-aheading of cl-yacc. CASE-SENSITIVE specifies interning C keywords or libc symbols is case-sensitively or case-insensitively. Expansion rules: - If VALUE is nil, no expansion is done. The original symbol is left. - If VALUE is a object not a function, it is used as an expansion. - If VALUE is a function, the function is called, and the returned value is used for expansion. Arguments for the function are datum between the following ( symbol and the next ) symbol, delimited by , symbol. Example: If MAC is defined for a macro and its value is a function, this sequence MAC ( a , b b , c c c ) calls the function like: (funcall #'a-func-of-MAC '(a) '(b b) '(c c c))
  • Type ENUM
    Represents the enum type.
  • Macro GET-VARIADIC-ARGUMENTS (&optional last-argument-name)
    It returns the variadic arguments of a function defined by with-c-syntax. If this is called outside of a variadic function, an error is signaled. When defining a variadic function, a local macro has same name is established. This is not intended for calling directly. The `va_start' macro uses this.

Also exports



with-c-syntax libc package.
  • Variable NDEBUG
  • Macro assert (&rest args)
    This emulates 'assert' of the C language. If `NDEBUG' is bound and its value is true, `|assert|' will be expanded to a no-op. If not (`NDEBUG' is unbound or bound to NIL), `|assert|' will be expanded to `cl:assert'. This macro sees `NDEBUG' value only when macroexpanding-time, not in runtime. (If you want to change `NDEBUG' locally, you should use `compiler-let'.)
  • Function isalnum (char)
  • Function isalpha (char)
  • Function islower (char)
  • Function isupper (char)
  • Function isdigit (char)
  • Function isxdigit (char)
  • Function iscntrl (char)
  • Function isgraph (char)
  • Function isspace (char)
  • Function isblank (char)
  • Function isprint (char)
  • Function ispunct (char)
  • Function tolower (char)
  • Function toupper (char)
  • Variable errno
    A symbol denoting 'errno' of C, or NIL. If a function of `with-c-syntax.libc' caught error, it will set the error to this. (If this has a symbol, that is usable as a condition type of 'osicat-posix'.)
  • Variable FLT_RADIX
    (float-radix 1.0d0)
  • Variable FLT_MANT_DIG
    (float-digits 1.0)
  • Variable FLT_EPSILON
  • Variable FLT_DIG
     with-c-syntax.libc:flt_mant_dig (float-radix 1.0) 10)
  • Variable FLT_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-single-float))
  • Variable FLT_MIN
  • Variable FLT_MIN_10_EXP
    (ceiling (log least-positive-normalized-single-float 10))
  • Variable FLT_MAX_EXP
    (nth-value 1 (decode-float most-positive-single-float))
  • Variable FLT_MAX
  • Variable FLT_MAX_10_EXP
    (floor (log most-positive-single-float 10))
  • Variable DBL_MANT_DIG
    (float-digits 1.0d0)
  • Variable DBL_EPSILON
  • Variable DBL_DIG
     with-c-syntax.libc:dbl_mant_dig (float-radix 1.0d0) 10)
  • Variable DBL_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-double-float))
  • Variable DBL_MIN
  • Variable DBL_MIN_10_EXP
    (ceiling (log least-positive-normalized-double-float 10))
  • Variable DBL_MAX_EXP
    (nth-value 1 (decode-float most-positive-double-float))
  • Variable DBL_MAX
  • Variable DBL_MAX_10_EXP
    (floor (log most-positive-double-float 10))
  • Variable LDBL_MANT_DIG
    (float-digits 1.0d0)
  • Variable LDBL_EPSILON
  • Variable LDBL_DIG
     with-c-syntax.libc:ldbl_mant_dig (float-radix 1.0d0) 10)
  • Variable LDBL_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-long-float))
  • Variable LDBL_MIN
  • Variable LDBL_MIN_10_EXP
    (ceiling (log least-positive-normalized-long-float 10))
  • Variable LDBL_MAX_EXP
    (nth-value 1 (decode-float most-positive-long-float))
  • Variable LDBL_MAX
  • Variable LDBL_MAX_10_EXP
    (floor (log most-positive-long-float 10))
  • Variable FLT_ROUNDS
  • Variable DECIMAL_DIG
    (max with-c-syntax.libc:flt_dig with-c-syntax.libc:dbl_dig
  • Variable FLT_EVAL_METHOD
  • Variable and
  • Variable and_eq
  • Variable bitand
  • Variable bitor
  • Variable compl
  • Variable not
  • Variable not_eq
  • Variable or
  • Variable or_eq
  • Variable xor
  • Variable xor_eq
  • Variable CHAR_BIT
  • Variable CHAR_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 8)
  • Variable CHAR_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 8)
  • Variable INT_MAX
  • Variable INT_MIN
  • Variable SHRT_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 16)
  • Variable SHRT_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 16)
  • Variable LONG_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 32)
  • Variable LONG_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 32)
  • Variable LLONG_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 64)
  • Variable LLONG_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 64)
  • Variable SCHAR_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 8)
  • Variable SCHAR_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 8)
  • Variable UCHAR_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 8)
  • Variable UINT_MAX
    (max most-positive-fixnum 65535)
  • Variable USHRT_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 16)
  • Variable ULONG_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 32)
  • Variable ULLONG_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 64)
  • Variable MB_LEN_MAX
    (ceiling (1+ (floor (log char-code-limit 2))) with-c-syntax.libc:char_bit)
  • Function fabs (x)
  • Function fmod (x y)
  • Function remainder (x y)
  • Function REMQUO* (x y)
  • Function fmax (x y)
  • Function fmin (x y)
  • Function exp (x)
  • Function exp2 (x)
  • Function expm1 (x)
  • Function log (x)
  • Function log10 (x)
  • Function log2 (x)
  • Function log1p (x)
  • Function pow (x y)
  • Function sqrt (x)
  • Function cbrt (x)
  • Function hypot (x y)
  • Function sin (x)
  • Function cos (x)
  • Function tan (x)
  • Function asin (x)
  • Function acos (x)
  • Function atan (x)
  • Function atan2 (x y)
  • Function sinh (x)
  • Function cosh (x)
  • Function tanh (x)
  • Function asinh (x)
  • Function acosh (x)
  • Function atanh (x)
  • Function ceil (x)
  • Function floor (x)
  • Function trunc (x)
  • Function round (x)
  • Function FREXP* (x)
  • Function ldexp (x exp)
  • Function MODF* (x)
  • Function scalbn (x exp)
  • Function ilogb (x)
  • Variable FP_ILOGB0
    (nth-value 1 (decode-float 0.0d0))
  • Function logb (x)
  • Function copysign (abs sign)
  • Variable HUGE_VAL
  • Variable HUGE_VALF
  • Variable HUGE_VALL
  • Variable INFINITY
  • Function isnan (x)
  • Function isinf (x)
  • Function isfinite (x)
  • Function isnormal (x)
  • Variable FP_NAN
  • Variable FP_INFINITE
  • Variable FP_ZERO
  • Variable FP_SUBNORMAL
  • Variable FP_NORMAL
  • Function fpclassify (x)
  • Function signbit (x)
  • Function lerp (a b v)
  • Macro va_start (ap last)
  • Macro va_end (ap)
  • Macro va_copy (dest src)
  • Variable NULL
    Holding `CL:NIL' for acting NULL of C language.
  • Function NULL (object)
    An alias for `CL:NULL'. This is for using 'NULL' as C constant and Lisp function both.
  • Variable offsetof
  • Function strcpy (dst src)
  • Function strncpy (dst src count)
  • Function strcat (dst src)
  • Function strncat (dst src count)
  • Function strlen (str)
  • Function strcmp (str1 str2)
  • Function strncmp (str1 str2 count)
  • Function strchr (str ch)
  • Function strrchr (str ch)
  • Function strspn (str accept)
  • Function strcspn (str reject)
  • Function strpbrk (str accept)
  • Function strstr (haystack needle)
  • Function strtok (str delim)
  • Function memchr (ptr ch count)
  • Function memcmp (lhs rhs count &key (test #'common-lisp:eql) (predicate #'common-lisp:<))
  • Function memset (dest ch count)
  • Function memcpy (dest src count)
  • Function memmove (dest src count)

Also exports



with-c-syntax libc implemetation package.
No exported symbols.