git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2009, 09:10 UTC
Message-ID
<7vbpsl8v7r.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<be6fef0d0903010052t50551f3w74352b69afdee620@mail.gmail.com>
Tay Ray Chuan <rctay89@gmail.com> writes:
Show 8 quoted lines
> #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;
    
Show 8 quoted lines
> #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?
Previous: Tay Ray ChuanNext: Tay Ray Chuan
Message 2 of 4 in “coding style: #ifdef blocks and real C blocks”
  1. Tay Ray ChuanMar 1, 2009
  2. Junio C HamanoMar 1, 2009
  3. Tay Ray ChuanMar 1, 2009
  4. Tay Ray ChuanMar 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.