Похожие чаты

Should I always check for NULL pointer? I have that

habit from c#.

17 ответов

63 просмотра

Yep

狐, シテ-- Vlad Автор вопроса
²
Yep

roger that

Is null valid to pass in?

I just assert not null

Chiyando
I just assert not null

It does work in "release" build?

I wouldn't

Just check for NULL at all callsites instead: assert(stack); push(stack, 42); and then step 2: remove the asserts at all callsites where it's obvious it's not NULL, like: stack_t stack = ...; push(&stack, 42); // no assert needed ofc

Thomas
Just check for NULL at all callsites instead: asse...

The theory is that step 2 will remove most or all assertions

Thomas
Just check for NULL at all callsites instead: asse...

You mean, just transfer responsibility for error/null checking to user?

²
You mean, just transfer responsibility for error/n...

No, he means don't check it at times when it is obviously not needed

²
You mean, just transfer responsibility for error/n...

Some functions take pointers that can be NULL, most don't, ones that don't shouldn't check, they should just segfault

狐, シテ-- Vlad Автор вопроса
Thomas
Some functions take pointers that can be NULL, mos...

Then, how do I unit test them if the app just segfaults? Or should I check only how it behaves given valid data? I'm just switching from C# to C and it highly contradicts how I used to work and deal with such situations since I treat pointers much like reference types in C# (it quite a bit helped me to get how they work) with addition that I should manually free the memory.

狐, シテ - Vlad
Then, how do I unit test them if the app just segf...

1. a segfault is a valid test suite failure, just not a very descriptive one 2. Yes, only test for valid data ofc, garbage in -> garbage out Imagine the scenario

狐, シテ-- Vlad Автор вопроса
Thomas
1. a segfault is a valid test suite failure, just ...

I will try that approach. Writing code expecting you will get in your functions what you want is new to me. Usually my code starts from a couple of if statements validating an input data.

狐, シテ - Vlad
I will try that approach. Writing code expecting y...

In this case validation is not free, and you usually control all the callsites too

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта