Thread: printf([dbl]Hello world[dbl]);

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    printf([dbl]Hello world[dbl]);

    Hi,
    this
    Code:
    printf([dbl]Hello world[dbl]);
    won't compile with c++ saying missing ")" in printf;

    p.s. (how come nearly space industry google strips those "[" "]" in a "[dbl]" request)

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Just to check: you actually included the relevant header file (i.e., <cstdio> or <stdio.h> for the C version) and used:
    Code:
    printf("Hello world");
    right?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    Code:
    #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;
    }
    please take a look at the above
    Last edited by pacific_flyway; 10-15-2009 at 07:13 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pacific_flyway
    well since c++ pre-processor does recognise printf evidently did so.
    What do you mean?

    Quote Originally Posted by pacific_flyway
    how do i know that [dbl] is just "double quote" should i define it myself somewhere? or it can be platform dependent?
    I have no idea why the book used '[dbl]' instead of '"'. You should be using actual double quotes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    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?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pacific_flyway
    Well I believe that there is a precompiler which does the including and syntax checking and many other things i cant remember.
    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.

    Quote Originally Posted by pacific_flyway
    So if that precompiler isnt able to translate [dbl] into the correct character it needs what is my role in that?
    To do it yourself. What book are you reading, anyway?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    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.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pacific_flyway
    But strictly theoreticaly, how is that possibe?

    printf([dbl]Hello world[dbl]);

    ? please ?
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    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.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pacific_flyway
    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++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #12
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    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.

  13. #13
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    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."

Popular pages Recent additions subscribe to a feed