* coding style: #ifdef blocks and real C blocks
@ 2009-03-01 8:52 Tay Ray Chuan
2009-03-01 9:10 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Tay Ray Chuan @ 2009-03-01 8:52 UTC (permalink / raw)
To: git
Hi,
I couldn't find any mention of #ifdef usage nor any example of how I'm
thinking of using #ifdef, so I'm posing this here.
Right now here's what I have on my local branch:
---
#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;
---
I want to implement an option that's stored in the variable
"persistent_connection", which basically makes the code behave as if
USE_CURL_MULTI isn't defined. (This would make git open/close less
connections throughout the lifespan of its execution, which would
remove/minimize the number of credential prompting if authentication
is required, among other advantages.)
Here's what I thought of:
---
#ifdef USE_CURL_MULTI
if (!persistent_connection)
slot = get_active_multi_slot();
else
slot = get_active_slot();
#else
slot = get_active_slot();
#endif
---
I thought of shortening this further to
---
#ifdef USE_CURL_MULTI
if (!persistent_connection)
slot = get_active_multi_slot();
else
#else
slot = get_active_slot();
#endif
slot->callback_func = process_response;
slot->callback_data = request;
request->slot = slot;
---
What would you suggest?
--
Cheers,
Ray Chuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: coding style: #ifdef blocks and real C blocks
2009-03-01 8:52 coding style: #ifdef blocks and real C blocks Tay Ray Chuan
@ 2009-03-01 9:10 ` Junio C Hamano
2009-03-01 9:27 ` Tay Ray Chuan
2009-03-01 9:33 ` Tay Ray Chuan
0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-03-01 9:10 UTC (permalink / raw)
To: Tay Ray Chuan; +Cc: git
Tay Ray Chuan <rctay89@gmail.com> 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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: coding style: #ifdef blocks and real C blocks
2009-03-01 9:10 ` Junio C Hamano
@ 2009-03-01 9:27 ` Tay Ray Chuan
2009-03-01 9:33 ` Tay Ray Chuan
1 sibling, 0 replies; 4+ messages in thread
From: Tay Ray Chuan @ 2009-03-01 9:27 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi,
On Sun, Mar 1, 2009 at 5:10 PM, Junio C Hamano <gitster@pobox.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: coding style: #ifdef blocks and real C blocks
2009-03-01 9:10 ` Junio C Hamano
2009-03-01 9:27 ` Tay Ray Chuan
@ 2009-03-01 9:33 ` Tay Ray Chuan
1 sibling, 0 replies; 4+ messages in thread
From: Tay Ray Chuan @ 2009-03-01 9:33 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Sun, Mar 1, 2009 at 5:10 PM, Junio C Hamano <gitster@pobox.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-01 9:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-01 8:52 coding style: #ifdef blocks and real C blocks Tay Ray Chuan
2009-03-01 9:10 ` Junio C Hamano
2009-03-01 9:27 ` Tay Ray Chuan
2009-03-01 9:33 ` Tay Ray Chuan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).