Actual output is <br><br>foo 20<br><br>the operator <tt>#</tt> causes the parameter to be replaced by a string literal <br><br>so mod(foo) becomes "foo"<br><br>and the xmod(foo) uses the value of foo which gives "20"<br>
<br>Mike<br><br><br><br><div class="gmail_quote">On Thu, Sep 22, 2011 at 2:39 PM, Yani Dubin <span dir="ltr"><<a href="mailto:yani.dubin@gmail.com">yani.dubin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I would assume it printed "20 20". But then that seems too obvious and<br>
I must be missing some sort of tricky business around preprocessor<br>
operator precedence causing something funky?<br>
<div><div></div><div class="h5"><br>
On Fri, Sep 23, 2011 at 9:12 AM, Andre Renaud <<a href="mailto:andre@bluewatersys.com">andre@bluewatersys.com</a>> wrote:<br>
> Unfortunately, as I don't tend to attend the local meetings I won't be<br>
> able to back this up with a Chocolate Fish. However, who can give the<br>
> correct output for the following C program, with an explanation for why.<br>
><br>
> #include <stdio.h><br>
> #include <string.h><br>
> #define xmod(s) mod(s)<br>
> #define mod(s) #s<br>
> #define foo 20<br>
><br>
> int main(int argc, char *argv[])<br>
> {<br>
> char buffer[20], buffer2[20];<br>
><br>
> strcpy(buffer, mod(foo));<br>
> strcpy(buffer2, xmod(foo));<br>
><br>
> printf("%s %s\n", buffer, buffer2);<br>
> return 0;<br>
> }<br>
><br>
> Regards,<br>
> Andre<br>
><br>
> _______________________________________________<br>
> Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br>
> <a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics" target="_blank">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
> Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
> Web site: <a href="http://kiwibots.org" target="_blank">http://kiwibots.org</a><br>
> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm<br>
><br>
> When replying, please edit your Subject line to reflect new content.<br>
><br>
<br>
_______________________________________________<br>
Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br>
<a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics" target="_blank">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
Web site: <a href="http://kiwibots.org" target="_blank">http://kiwibots.org</a><br>
Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm<br>
<br>
When replying, please edit your Subject line to reflect new content.<br>
</div></div></blockquote></div><br>