-6

I'm coming back to 'C' after few years. I searched the net for how to use Twitter API in C and I came across this question on stackoverflow.

Question: Accessing the Twitter Streaming API with C

I can't understand the "if" in this code:

if(curl) {

I can't understand it, what does it do? What is it's function? Shouldn't there be some conditional?

Please help. Thanks

Community
  • 1
  • 1
want2code
  • 11
  • 1

3 Answers3

0

It checks to see if the pointer curl is not null (a null pointer is equivalent to the value 0, which is false when considered as a Boolean).

Blair Conrad
  • 233,004
  • 25
  • 132
  • 111
0

You should have looked at the previous three lines,

CURL *curl;
CURLcode res;

curl = curl_easy_init();
if(curl) {

In the above code, did curl_easy_init() succeed in initialization.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

In C language, there are no actual booleans. But 0 and 1 can be treated as booleans in C language.. where 0 is false and anything nonzero is true including negative numbers. So this curl is a pointer and is assigned zero if not initialized. Hence it checks if curl is initialized and if it is.. if block gets executed

Prashanthv
  • 109
  • 7