Hi,
this
won't compile with c++ saying missing ")" in printf;Code:printf([dbl]Hello world[dbl]);
p.s. (how come nearly space industry google strips those "[" "]" in a "[dbl]" request)
Thanks
Hi,
this
won't compile with c++ saying missing ")" in printf;Code:printf([dbl]Hello world[dbl]);
p.s. (how come nearly space industry google strips those "[" "]" in a "[dbl]" request)
Thanks
Just to check: you actually included the relevant header file (i.e., <cstdio> or <stdio.h> for the C version) and used:
right?Code:printf("Hello world");
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
please take a look at the aboveCode:#include <stdio.h> #include <string.h> #include <stdlib.h> #define SKROOGE int main (void) { char *p; #ifdef SKROOGE p = malloc(strlen([dbl]Hello World[dbl]) + 1); #else p = malloc(1000); #endif if(p != NULL) { strcpy(p, [dbl]Hello World[dbl]); printf([dbl]%s\n[dbl], p); free(p); } return 0; }
Last edited by pacific_flyway; 10-15-2009 at 07:13 AM.
What do you mean?Originally Posted by pacific_flyway
I have no idea why the book used '[dbl]' instead of '"'. You should be using actual double quotes.Originally Posted by pacific_flyway
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Well I believe that there is a precompiler which does the including and syntax checking and many other things i cant remember. Then it goes down to the actual compiler which makes the actual instructions and the linker which links the object into an application.
So if that precompiler isnt able to translate [dbl] into the correct character it needs what is my role in that?
Well, yes, the preprocessor will process the includes and handle macro substitution (but not syntax checking), but '[dbl]' is not even a valid macro name. Even if you changed it to just 'dbl', I doubt that would work.Originally Posted by pacific_flyway
To do it yourself. What book are you reading, anyway?Originally Posted by pacific_flyway
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Interestingly later in the book the actual '"' double quotes characters are used in the code. I think i should rather not recompile the compiler as well.
But strictly theoreticaly, how is that possibe?
printf([dbl]Hello world[dbl]);
Ironicly the books title is [dbl]C Unleashed[dbl] by SAMS
Last edited by pacific_flyway; 10-15-2009 at 07:36 AM.
It might be possible with imaginative use of macros (but I am not creative enough) and it is certainly possible with the use of a custom preprocessor, but other than that I am inclined to say that you should simply ignore it as an error in the book.Originally Posted by pacific_flyway
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
You know what
i dont know what to say i wish i could safely assume that [dbl] can be just a typo or automation related mistake and the actual double quotes character was meant to be inplace, since this example doesnt introduce me to any fundamental task solving approach and the main idea was to show the use of pointers. but i cant.
In my opinion, if you really feel that you cannot make that assumption, then your best option is to throw that book away (or return it to the library, etc). Read one of our recommended books instead, e.g., Accelerated C++.Originally Posted by pacific_flyway
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I don't think you can trick the preprocessor to accept such a thing. Perhaps, for whatever reason at some point the author or editors felt they couldn't use the " symbol and replaced them with the placeholder [dbl] which they then forgot to convert back everywhere.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Well actualy there is a way to extend and reshape lexer tokens designing a custom preprocessor. Somehow i had a bad feeling giving you this wonderfull Heathfield Kirby book name.
I hope i will read [link]our recommended books[/link] some day to see if they have a reference to a custom preprocessor prior to explaining pointers.
And thank you for your help. I would be continuously puzzled over that.
Last edited by pacific_flyway; 10-15-2009 at 08:47 AM.
Wow.
Just wow.
Google translate is really not a gift to the internet.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."