[chbot] C Challange #6
Michael Pearce
mike at kiwacan.co.nz
Thu Sep 22 23:01:14 BST 2011
Actual output is
foo 20
the operator # causes the parameter to be replaced by a string literal
so mod(foo) becomes "foo"
and the xmod(foo) uses the value of foo which gives "20"
Mike
On Thu, Sep 22, 2011 at 2:39 PM, Yani Dubin <yani.dubin at gmail.com> wrote:
> I would assume it printed "20 20". But then that seems too obvious and
> I must be missing some sort of tricky business around preprocessor
> operator precedence causing something funky?
>
> On Fri, Sep 23, 2011 at 9:12 AM, Andre Renaud <andre at bluewatersys.com>
> wrote:
> > Unfortunately, as I don't tend to attend the local meetings I won't be
> > able to back this up with a Chocolate Fish. However, who can give the
> > correct output for the following C program, with an explanation for why.
> >
> > #include <stdio.h>
> > #include <string.h>
> > #define xmod(s) mod(s)
> > #define mod(s) #s
> > #define foo 20
> >
> > int main(int argc, char *argv[])
> > {
> > char buffer[20], buffer2[20];
> >
> > strcpy(buffer, mod(foo));
> > strcpy(buffer2, xmod(foo));
> >
> > printf("%s %s\n", buffer, buffer2);
> > return 0;
> > }
> >
> > Regards,
> > Andre
> >
> > _______________________________________________
> > Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> > http://lists.ourshack.com/mailman/listinfo/chchrobotics
> > Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> > Web site: http://kiwibots.org
> > Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale
> Ave, 6.30pm
> >
> > When replying, please edit your Subject line to reflect new content.
> >
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Web site: http://kiwibots.org
> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale
> Ave, 6.30pm
>
> When replying, please edit your Subject line to reflect new content.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ourshack.com/pipermail/chchrobotics/attachments/20110922/61830d65/attachment.htm
More information about the Chchrobotics
mailing list