Types and VariablesΒΆ
var = CVariable(
c_type=Cint8,
name="i8Mycustomint",
initial_value=4,
doc=Doc("My Custom Int8")
)
print(var.declaration())
/** @brief My Custom Int8 */
int8_t i8Mycustomint = 4;
try:
var = CVariable(
c_type=Cuint8,
name="i8Mycustomint_invalid",
initial_value=500
)
except Exception as ex:
print(ex)
Initial value [500] does not fit type [uint8_t]
array = CArray(
c_type=Cint8,
name="i8Asdf",
length=10,
doc=Doc("My Custom Int8 Array", "This array is awesome because it can hold 10 int8")
)
print(array.declaration())
/**
* @brief My Custom Int8 Array
*
* This array is awesome because it can hold 10 int8
*/
int8_t i8Asdf[10];
# New type
custom = Cint8.type('TMyCustomType')
var = CVariable(
c_type=custom,
name="tMyVar"
)
print(custom.typedef(doc=Doc("My Custom Type", "Awesome type because I have defined it")).render())
print(var.declaration())
/**
* @brief My Custom Type
*
* Awesome type because I have defined it
*/
typedef int8_t TMyCustomType;
TMyCustomType tMyVar;
# Static
var = CVariable(c_type=Cuint8, name="u8Var", static=True)
print(var.declaration())
static uint8_t u8Var;
# Static and const
var = CVariable(c_type=Cuint8, name="u8Var", static=True, const=True)
print(var.declaration())
static const uint8_t u8Var;
# Constexpr
var = CVariable(c_type=Cuint8, name="u8Var", constexpr=True)
print(var.declaration())
constexpr uint8_t u8Var;