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

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:18

Tay Ray Chuan [off-list ref] 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?

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

From: Tay Ray Chuan <hidden>
Date: 2016-06-15 22:46:18

Hi,

On Sun, Mar 1, 2009 at 5:10 PM, Junio C Hamano [off-list ref] wrote:
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
Nice.
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?
Hmm, so I just do "slot = active_persistent_slot()" ?

-- 
Cheers,
Ray Chuan

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

From: Tay Ray Chuan <hidden>
Date: 2016-06-15 22:46:18

On Sun, Mar 1, 2009 at 5:10 PM, Junio C Hamano [off-list ref] wrote:
   #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?
On further thought, wouldn't it be a better idea to make this
uppercase, ie. GET_ACTIVE_SLOT, to make it more obvious this is a
macro? Then we wouldn't have to jumble the name into "active_slot_get"
to differentiate it from the two slot functions.

-- 
Cheers,
Ray Chuan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help