Created
August 22, 2024 21:19
C - How to check nonnull parameter during compile time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void action(char *a, char *b) __attribute__((nonnull(2))); | |
void action(char *a, char *b) { | |
if (a != NULL) { | |
printf("%s\n", a); | |
} | |
printf("%s\n", b); | |
} | |
int main() { | |
char *a = (char *)malloc(sizeof(char) + 1); | |
strcpy(a, "t"); | |
action(a, a); | |
action(NULL, a); | |
action(a, NULL); | |
} |
Author
mortymacs
commented
Aug 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment