Like Tree1Likes
  • 1 Post By laserlight

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

This is a discussion on printf([dbl]Hello world[dbl]); within the C++ Programming forums, part of the General Programming Boards category; Hi, this Code: printf([dbl]Hello world[dbl]); won't compile with c++ saying missing ")" in printf; p.s. (how come nearly space industry ...

  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
    21,739
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,739
    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.
    Flare likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,739
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,739
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,739
    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++.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    478
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21