cd /news/developer-tools/assert-default-params-c · home topics developer-tools article
[ARTICLE · art-8806] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

assert_default_params.c

The file `assert_default_params.c` defines a custom `assert` macro that supports optional error messages by wrapping an `assert_func` function, which prints a failure message to stderr and calls `abort()` if a condition is false. The `main` function demonstrates this by asserting that `argc` is greater than zero and that `argv[0]` is not null, with the second assertion including a custom error string. This code illustrates a technique for adding descriptive assertions in C using variadic macros.

read1 min views26 publishedFeb 1, 2021

assert_default_params.c

  This file contains hidden or 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

Show hidden characters

void

assert_func ( int

cond , const

char

msg

) { if (! cond

) { fprintf ( stderr , "assert failed: %s\n" , msg

); abort

();

    }

}

#define

assert_helper ( x , y

, ...) assert_func(x, y) #define

assert ( x

, ...) assert_helper((x), ## VA_ARGS, #x) int

main ( int

argc , char

argv

) { assert ( argc

0

); assert ( argv [ 0 ] !=

0 ,

"argv[0] cannot be null"
);

}
── more in #developer-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/assert-default-param…] indexed:0 read:1min 2021-02-01 ·