Re: coding style: #ifdef blocks and real C blocks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tay Ray Chuan <rctay89@xxxxxxxxx> writes:

> #ifdef USE_CURL_MULTI
> 	slot = get_active_multi_slot();
> #else
> 	slot = get_active_slot();
> #endif
> 	slot->callback_func = process_response;
> 	slot->callback_data = request;
> 	request->slot = slot;

How about doing something like this:

    #ifdef USE_CURL_MULTI
    #define active_slot_get get_active_multi_slot
    #else
    #define active_slot_get get_active_slot
    #endif

so that the code itself would not have to have any #ifdef?

    slot = active_slot_get()
    slot->callback_func = process_response;
    slot->callback_data = request;
    request->slot = slot;
    
> #ifdef USE_CURL_MULTI
> 	if (!persistent_connection)
> 		slot = get_active_multi_slot();
> 	else
> 		slot = get_active_slot();
> #else
> 	slot = get_active_slot();
> #endif

Similarly, with something like this:

    #ifdef USE_CURL_MULTI
    slot active_persistent_slot() {
            return persistent_connection ? get_active_slot() : get_active_multi_slot();
    }
    #else
    slot active_persistent_slot() {
            return get_active_slot();
    }
    #endif

the call site can be #ifdef free, no?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux