Error condition in C

Asked

Viewed 51 times

2

When I moved in Python I remember I had how to make one if if any assignment or operation returned error. Type like this

int v[]={1,2};
int v1;
if((v1=v)==ERRO)
    //faça isso;

There’s something like this in C?

  • You mean if((v1==v) == ERRO), right?

  • 1

    @Magichat no, this syntax does not exist.

  • Nusssa brizei, num has nor logic...

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

2

C is a so-called static language, and weak typing, is the opposite of Python which is dynamic and strong. You cannot change a type of variable, as you can in Python, but you can interpret one data as if it were another. It is the programmer’s function to solve this in the code.

Actually this is a programming error, so you should fix it and not try to check in the code if it went all right. If it were another example it might be that it would make sense to make a check, but not in that.

To be honest, I think this code even written in Python would be really bad and possibly a mistake too, but I don’t know, there might be a context that I don’t know.

Depending on the compiler and configuration this will give build error, so you don’t even have to do this.

See on ideone that neither compiles.

  • I don’t even remember seeing this in Python. I believe the syntax is not even valid. In PHP it is very common to do, for example, if ($row = $query->fetch_array()) {}.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.