On 08/20/16 02:10 PM, Rick C. Hodgin wrote:
> On Friday, August 19, 2016 at 9:15:59 PM UTC-4, Ian Collins wrote:
>> On 08/20/16 01:09 PM, Rick C. Hodgin wrote:
>>> On Friday, August 19, 2016 at 6:14:30 PM UTC-4, Ian Collins wrote:
>>>> On 08/20/16 09:56 AM, BartC wrote:
>>>>> On 19/08/2016 22:36, Ian Collins wrote:
>>>>>> On 08/20/16 09:22 AM, Rick C. Hodgin wrote:
>>>>>>> I tried to do this today, and the compiler balked. Is there a syntax
>>>>>>> where this idea is legal (line 06 and the [c = "hello"] part)?
>>>>>>>
>>>>>>> 01: void myfunc(int value, char* text)
>>>>>>> 02: {
>>>>>>> 03: printf("%d %s\n", value, text);
>>>>>>> 04: }
>>>>>>> 05:
>>>>>>> 06: #define abc(a, b, c = "hello") a(b, c)
>>>>>>> 07:
>>>>>>> 08: abc(myfunc, 2);
>>>>>>
>>>>>> If you want C++, you know where to find it!
>>>>>
>>>>> I tried it in C++ and it didn't seem to work.
>>>>
>>>> In C++, we don't use macros.
>>>>
>>>> A function template like
>>>>
>>>> template <typename Fn, typename B>
>>>> void abc( Fn a, B b, const char* c = "hello") { a(b, c); }
>>>>
>>>> would be used.
>>>
>>> 01: void myfunc(int value, char* text)
>>> 02: {
>>> 03: printf("%d %s\n", value, text);
>>> 04: }
>>> 05:
>>> 06: #define abc(a, b, c = "no param given") a(b, c)
>>> 07:
>>> 08: abc(myfunc, 2);
>>> 09: abc(myfunc, 5, "five");
>>
>> # cat x.cc
>> #include <stdio.h>
>>
>> void myfunc(int value, const char* text)
>> {
>> printf("%d %s\n", value, text);
>> }
>>
>> template <typename Fn, typename B>
>> void abc( Fn a, B b, const char* c = "no param given" ) { a(b, c); }
>>
>> int main()
>> {
>> abc(myfunc, 2);
>> abc(myfunc, 5, "five");
>> }
>>
>> # CC x.cc; ./a.out;
>> 2 no param given
>> 5 five
>
> I appreciate your response, Ian. There are things about this I don't
> understand, but since it's clc, I'll let it go.
Seeing as you also asked there, I've cross-posted to c.l.c++ so you can
follow up there.
--
Ian