Checks in bit.c

Checks in bit.c

par Joshua Nicholas Pierre Bernimoulin,
Number of replies: 6

Hello, 

we were wondering if we should implement checks in bit.c as we did in alu.c or should we consider that these checks will have been done at a higher level? If we do have to do the checks , how do we implement the error case since these do not have a return types (void fuctions)?

Thank you 

Joshua

In reply to Joshua Nicholas Pierre Bernimoulin

Re: Checks in bit.c

par Deleted user,

Hello,

You definitely need to check the parameters of the functions in bit.c. As you pointed out, those functions have no return value. Therefore, there is no way to return an error code whether by a return value (or even through an output parameter). So in this case, you just need to return to the caller.

In reply to Deleted user

Re: Checks in bit.c

par Joshua Nicholas Pierre Bernimoulin,

Thank you

Is it alright if we put a message in stderr in those cases?

In reply to Joshua Nicholas Pierre Bernimoulin

Re: Checks in bit.c

par Jean-Cédric Chappelier,

Le mieux pour tout ça est d'utiliser les macros fournies dans error.h (M_REQUIRE, M_EXIT, ...) ou, si vraiment nécessaire, la macro debug_print

In reply to Deleted user

Re: Checks in bit.c

par Aman Bansal,

1/ Est-ce que c'est permis d'utiliser M_EXIT pour les fonctions void ? Parce que M_EXIT va retourner un code d'erreur même si on ne doit rien retourner dans une fonction void.

2/ Est-ce que ce type d'appel à la fonction M_EXIT est permis ? "M_EXIT(/*pas de code*/, "commentaire");

3/ Sinon, est-ce qu'on peut juste utiliser debug_print(...) et puis return ?

Merci en avance !

In reply to Aman Bansal

Re: Checks in bit.c

par Deleted user,

Bonjour,

  1. Cela compilera et vous aurez juste un warning suivant les flags de compilation que vous utilisez.
  2. Non, il n'y a pas de variante M_EXIT sans code d'erreur, mais vous pouvez définir cette macro si vous le souhaitez.
  3. Oui, vous pouvez.