Похожие чаты

Should I always check for NULL pointer? I have that

habit from c#.

17 ответов

36 просмотров

Yep

狐-- えんきどぅ Автор вопроса
²
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

狐-- えんきどぅ Автор вопроса
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.

狐 - えんきどぅ
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

狐-- えんきどぅ Автор вопроса
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.

狐 - えんきどぅ
I will try that approach. Writing code expecting y...

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

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

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

Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
We heading to 1.1$ 🤔?
CryptoBo$$
35
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
46
Всем здравствуйте!) У меня такой вопрос. Есть два роута, роут1 и роут2. Они связаны с очередью some_queue. По задаче предполагается, что есть два паблиша. Паблиш1 отправляет...
Format
10
i justHey. Im holding kadena almost 3 years now. Its my only investment what isn't in profit. But i thought for years that its just need some more time but i haven't seen that...
Riki
7
Сonst magicTgHTML = (text, entities) => { let processedText = text; let offsetShift = 0; entities.forEach(entity => { const { offset, length, type, url, ...
Андрей
1
Вопрос по WIN32: Насколько я понимаю то все функции win32 привязаны к объектам операционной системы. Например консоль, файл, кисть, окна итд. Следовательно функции win32 упра...
Tommy Vercetti
6
remote nodes with vpn or tor still safe ? (or they can collect other information like amount, receiving/sending adress, .. ?)
Tchoupi
12
кто-то пользуется компонентами rx ? как их лучше ставить, через OPM? (lazarus)
Iluha Companets
15
В смысле более затратная? Общая стоимость владения лошадью меньше, чем автомобиля. В среднем.
Sergej R
10
Карта сайта