Skip to content

Commit 95c6f94

Browse files
ygeyzellpil
authored andcommitted
c: add assertions and dynamic allocation snippets
1 parent f1b72d8 commit 95c6f94

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

snippets/c.snippets

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,33 @@ snippet getopt
334334
${0}
335335
}
336336
}
337+
338+
## Assertions
339+
snippet asr
340+
assert(${1:condition});
341+
342+
snippet anl
343+
assert(${1:ptr} != NULL);
344+
345+
## Dynamic Allocation
346+
snippet mlc
347+
${1:ptr} = (${2:type}*) malloc(sizeof($2));
348+
349+
snippet clc
350+
${1:ptr} = (${2:type}*) calloc(${3:size}, sizeof($2));
351+
352+
snippet rlc
353+
${1:ptr} = realloc($1, ${2:size} * sizeof(${3:type}));
354+
355+
snippet mlcd
356+
${1:type} ${2:ptr} = ($1*) malloc(sizeof($1));
357+
358+
snippet clcd
359+
${1:type} ${2:ptr} = ($1*) calloc(${3:size}, sizeof($1));
360+
361+
snippet fre
362+
free(${1:ptr});
363+
337364
##
338365
# TODO section
339366
snippet todo

0 commit comments

Comments
 (0)