Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Syntax Error

Syntax Error

Scheduled Pinned Locked Moved The Lounge
helpquestion
29 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dandy72

    It's been years I've written as much as a Hello World in C++; would all modern parsers be 100% okay with the fact that there's no space between the #include and the following ?

    0 Offline
    0 Offline
    0x01AA
    wrote on last edited by
    #3

    Just tried it with a 20 year old borland c++ compiler and it accepts

    #include
    #include"Mainwindow.h"

    ;)

    D 1 Reply Last reply
    0
    • 0 0x01AA

      Just tried it with a 20 year old borland c++ compiler and it accepts

      #include
      #include"Mainwindow.h"

      ;)

      D Offline
      D Offline
      dandy72
      wrote on last edited by
      #4

      Now throw Resharper at it. It'll bitch and complain until you fix it or disable the check. I like R# for some of its suggestions, but sometimes it goes overboard and annoys me to no end.

      1 Reply Last reply
      0
      • D dandy72

        It's been years I've written as much as a Hello World in C++; would all modern parsers be 100% okay with the fact that there's no space between the #include and the following ?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        You can write an entire C/C++ program on a single line, which is why all those punctuation characters are so important.

        Mircea NeacsuM D 2 Replies Last reply
        0
        • D dandy72

          It's been years I've written as much as a Hello World in C++; would all modern parsers be 100% okay with the fact that there's no space between the #include and the following ?

          K Offline
          K Offline
          k5054
          wrote on last edited by
          #6

          A sampling of compilers at [Compiler Explorer](https://godbolt.org/) were happy without spaces. Have to admit that it just looks wrong to me. But then I'm an old fogey ...

          "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

          D 1 Reply Last reply
          0
          • L Lost User

            You can write an entire C/C++ program on a single line, which is why all those punctuation characters are so important.

            Mircea NeacsuM Offline
            Mircea NeacsuM Offline
            Mircea Neacsu
            wrote on last edited by
            #7

            Richard MacCutchan wrote:

            You can write an entire some C/C++ programs on a single line,

            FTFY Sometimes you cannot:

            #define A "Hello world!\n"
            int main(int argc, char** argv)
            {
            printf (A);
            return 0;
            }

            When discussion comes to blanks and line endings I always remember a funny picture from an old book.

            Mircea

            Richard Andrew x64R P 2 Replies Last reply
            0
            • Mircea NeacsuM Mircea Neacsu

              Richard MacCutchan wrote:

              You can write an entire some C/C++ programs on a single line,

              FTFY Sometimes you cannot:

              #define A "Hello world!\n"
              int main(int argc, char** argv)
              {
              printf (A);
              return 0;
              }

              When discussion comes to blanks and line endings I always remember a funny picture from an old book.

              Mircea

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #8

              Well technically, the #define is not part of the program, is it?

              The difficult we do right away... ...the impossible takes slightly longer.

              Mircea NeacsuM H 2 Replies Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                Well technically, the #define is not part of the program, is it?

                The difficult we do right away... ...the impossible takes slightly longer.

                Mircea NeacsuM Offline
                Mircea NeacsuM Offline
                Mircea Neacsu
                wrote on last edited by
                #9

                I would say that "technically", the preprocesor is part of the language (preprocessor is defined in K&R), hence #define is part of the program. However, I'm not going to start a war here about such minutia, and specially not with such nice people. :)

                Mircea

                Richard Andrew x64R 1 Reply Last reply
                0
                • Mircea NeacsuM Mircea Neacsu

                  Richard MacCutchan wrote:

                  You can write an entire some C/C++ programs on a single line,

                  FTFY Sometimes you cannot:

                  #define A "Hello world!\n"
                  int main(int argc, char** argv)
                  {
                  printf (A);
                  return 0;
                  }

                  When discussion comes to blanks and line endings I always remember a funny picture from an old book.

                  Mircea

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #10

                  There exists at least one C/C++ program which can be written in one line. I try to avoid putting any pre-processor directives in my C/C++ files -- an include can be specified at the command line for the compilers I use. I somewhat agree that the language of C/C++ and its pre-processor are separate languages. One can create any number of alternative pre-processor languages -- K&R's is just one. Maybe you haven't used Oracle's PRO*C or RDB's version for embedding SQL in C/C++ programs. One thing I want in a pre-processor is the ability to tell it which directives to process and which to leave for later. I have had to jump through hoops to get things to work the way I want. And I do like lots of SPACEs which are not "required": # include # include "Mainwindow.h"

                  Mircea NeacsuM 1 Reply Last reply
                  0
                  • L Lost User

                    You can write an entire C/C++ program on a single line, which is why all those punctuation characters are so important.

                    D Offline
                    D Offline
                    dandy72
                    wrote on last edited by
                    #11

                    Agreed, but I'm not sure all tokenizers would be happy with the lack of a space, which in this case might be considered as significant as a punctuation character. But then, I suppose when you see something starting with "#include", the next character really should not be part of that token. Especially when it's a reserved character such as < or ", so I suppose the situation is easy enough to detect and allow.

                    H J 2 Replies Last reply
                    0
                    • K k5054

                      A sampling of compilers at [Compiler Explorer](https://godbolt.org/) were happy without spaces. Have to admit that it just looks wrong to me. But then I'm an old fogey ...

                      "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                      D Offline
                      D Offline
                      dandy72
                      wrote on last edited by
                      #12

                      k5054 wrote:

                      Compiler Explorer

                      Of *course* that had to exist. So, this is the source code equivalent to VirusTotal... Very neat. Thanks for that link.

                      1 Reply Last reply
                      0
                      • Richard Andrew x64R Richard Andrew x64

                        Well technically, the #define is not part of the program, is it?

                        The difficult we do right away... ...the impossible takes slightly longer.

                        H Offline
                        H Offline
                        honey the codewitch
                        wrote on last edited by
                        #13

                        If it's not, then neither is #include

                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                        Richard Andrew x64R P 2 Replies Last reply
                        0
                        • P PIEBALDconsult

                          There exists at least one C/C++ program which can be written in one line. I try to avoid putting any pre-processor directives in my C/C++ files -- an include can be specified at the command line for the compilers I use. I somewhat agree that the language of C/C++ and its pre-processor are separate languages. One can create any number of alternative pre-processor languages -- K&R's is just one. Maybe you haven't used Oracle's PRO*C or RDB's version for embedding SQL in C/C++ programs. One thing I want in a pre-processor is the ability to tell it which directives to process and which to leave for later. I have had to jump through hoops to get things to work the way I want. And I do like lots of SPACEs which are not "required": # include # include "Mainwindow.h"

                          Mircea NeacsuM Offline
                          Mircea NeacsuM Offline
                          Mircea Neacsu
                          wrote on last edited by
                          #14

                          PIEBALDconsult wrote:

                          an include can be specified at the command line for the compilers I use

                          Interesting! I know how to specify an include path but not a file.

                          PIEBALDconsult wrote:

                          Maybe you haven't used Oracle's PRO*C or RDB's version for embedding SQL in C/C++ programs.

                          No, never! I've been fortunate in that respect ;P The closest I got was using SQLITE :D

                          Mircea

                          P 1 Reply Last reply
                          0
                          • H honey the codewitch

                            If it's not, then neither is #include

                            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                            Richard Andrew x64R Offline
                            Richard Andrew x64R Offline
                            Richard Andrew x64
                            wrote on last edited by
                            #15

                            Completely agree.

                            The difficult we do right away... ...the impossible takes slightly longer.

                            1 Reply Last reply
                            0
                            • Mircea NeacsuM Mircea Neacsu

                              I would say that "technically", the preprocesor is part of the language (preprocessor is defined in K&R), hence #define is part of the program. However, I'm not going to start a war here about such minutia, and specially not with such nice people. :)

                              Mircea

                              Richard Andrew x64R Offline
                              Richard Andrew x64R Offline
                              Richard Andrew x64
                              wrote on last edited by
                              #16

                              Would you care to discuss tabs v. spaces? :)

                              The difficult we do right away... ...the impossible takes slightly longer.

                              H 1 Reply Last reply
                              0
                              • Richard Andrew x64R Richard Andrew x64

                                Would you care to discuss tabs v. spaces? :)

                                The difficult we do right away... ...the impossible takes slightly longer.

                                H Offline
                                H Offline
                                honey the codewitch
                                wrote on last edited by
                                #17

                                *Python has entered the chat*

                                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                1 Reply Last reply
                                0
                                • H honey the codewitch

                                  If it's not, then neither is #include

                                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #18

                                  Correct. Pre-processor directives are resolved before the code reaches the actual C/C++ compiler. The output of whatever pre-processor(s) you use is the actual code. Or -- as I do -- use a C/C++ pre-processor to resolve directives I put in C# and pass the result to the C# compiler. But you know that.

                                  H 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Correct. Pre-processor directives are resolved before the code reaches the actual C/C++ compiler. The output of whatever pre-processor(s) you use is the actual code. Or -- as I do -- use a C/C++ pre-processor to resolve directives I put in C# and pass the result to the C# compiler. But you know that.

                                    H Offline
                                    H Offline
                                    honey the codewitch
                                    wrote on last edited by
                                    #19

                                    I do. I am open to the reasonable disagreement about whether or not the preprocessor is part of the language, even if not part of the compiler itself. I think either position is valid, depending on which rubber ruler you use, and so I'm not really about debating that, but I think that's the question here.

                                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                    P J 2 Replies Last reply
                                    0
                                    • Mircea NeacsuM Mircea Neacsu

                                      PIEBALDconsult wrote:

                                      an include can be specified at the command line for the compilers I use

                                      Interesting! I know how to specify an include path but not a file.

                                      PIEBALDconsult wrote:

                                      Maybe you haven't used Oracle's PRO*C or RDB's version for embedding SQL in C/C++ programs.

                                      No, never! I've been fortunate in that respect ;P The closest I got was using SQLITE :D

                                      Mircea

                                      P Offline
                                      P Offline
                                      PIEBALDconsult
                                      wrote on last edited by
                                      #20

                                      Mircea Neacsu wrote:

                                      but not a file

                                      If I recall correctly, with VAX/DEC/Compaq/HP C the switch is /FirstInclude. I don't have an installation of Microsoft's C/C++ compiler on this system -- nor Borland's C/C++ or GCC -- but I can try to have a look when I get home. MingW: An example from Implanting Common Code in Unrelated Classes[^] "C:\mingw\bin\cpp" -P -C -include "c:\batfiles\ImplantWarning.h" D__NAME_SPACE__=%3 -D__CLASS_NAME__=%4 -w "%1" "%2" I'm sure I have it for Microsoft's C/C++ compiler (cl.exe) as well. I have probably referred to it in the past. Oh!: Re: c program - C / C++ / MFC Discussion Boards[^] F:\Projects>cl.exe /nologo /FIstdio.h /DSEMI=; nosem.c

                                      Mircea NeacsuM 1 Reply Last reply
                                      0
                                      • D dandy72

                                        Agreed, but I'm not sure all tokenizers would be happy with the lack of a space, which in this case might be considered as significant as a punctuation character. But then, I suppose when you see something starting with "#include", the next character really should not be part of that token. Especially when it's a reserved character such as < or ", so I suppose the situation is easy enough to detect and allow.

                                        H Offline
                                        H Offline
                                        honey the codewitch
                                        wrote on last edited by
                                        #21

                                        It wouldn't be part of the token in most tokenizer implementations. "include" would be a preproc keyword.** ** or identifier if the tokenizer doesn't distinguish between idents and keywords as is often the case. Most of the time, whitespace is hidden during tokenization before the parser gets to it so the parser wouldn't really care if there was no whitespace unless the developer put in extra effort for it to care.

                                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                        1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          I do. I am open to the reasonable disagreement about whether or not the preprocessor is part of the language, even if not part of the compiler itself. I think either position is valid, depending on which rubber ruler you use, and so I'm not really about debating that, but I think that's the question here.

                                          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #22

                                          Yep, but I think I further irk you by using it for purposes other than its original intent.

                                          H 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups