ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Some questions about C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some questions about C++

    Hi everyone. Let me ask you why this forum does not have a section for discussing questions about the C and C++ programming languages? It seems to me very convenient to use C++ if you create classes for the system objects (such as *FILE, *DTAARA, *MSGF and others).
    Or is there some good reason why C++ is not used to create programs for IBM i? Then why did IBM create and maintain a C++ compiler on the system?

  • #2
    IBM uses C/C++ within the operating system. Some of the ISVs and tool vendors use C/C++ as well to create and maintain their products. (I'm one of the latter.)

    That said, the vast majority of IBM i development is business application, and languages such as RPG or Cobol are a better fit vs. lower-level languages like C/C++. So only a small percentage of IBM i development is done in C/C++. But, as its an important percentage, they maintain the compilers.

    Comment


    • #3
      I don’t want to argue, but I don’t consider C++ a lower level language than RPG. On the contrary, I believe that C++ is a higher-level language compared to RPG (I did not program on COBOL).
      Scott, tell me, have you used C or C++ in your products? Or both? I have a question on C++.
      The IBM help (which applies to both C and C++) indicates that if only the name of a member is specified when the header file is included, then this member is searched first of all in the same file where the member with this inclusion directive is located. However, this rule only works in a C code. The C++ preprocessor with this method of inclusion does not find the member. I have version 7.4 system. Tell me, is this a system bug or I misunderstood something in the help?

      Comment


      • #4
        Originally posted by d7d1cd_ View Post
        Scott, tell me, have you used C or C++ in your products? Or both? I have a question on C++.
        Our products use C++. I coded C in a prior job, so I've done both.

        Originally posted by d7d1cd_ View Post
        The IBM help (which applies to both C and C++) indicates that if only the name of a member is specified when the header file is included, then this member is searched first of all in the same file where the member with this inclusion directive is located. However, this rule only works in a C code. The C++ preprocessor with this method of inclusion does not find the member. I have version 7.4 system. Tell me, is this a system bug or I misunderstood something in the help?
        I must admit, I haven't tried that. We always explicitly list the filename. For example:
        Code:
        #include "profoundui.h"
        When I first started coding ILE C/C++ it very much surprised me that the ".h" is considered the source file name. Even stranger is that you can do stuff like this:

        Code:
        #include <mih/cvtch.h>
        In this case, the .h isn't the filename, the filename is "mih". And indeed, the member need not end in ".h". I found that very confusing and inconsistent when I started with this stuff. But, anyway... we've always listed the filename explicitly, so I don't know what happens when you just use the member name. If you think it's wrong, I'd suggest opening a case with IBM.

        Comment


        • #5
          Originally posted by Scott Klement View Post
          But, anyway... we've always listed the filename explicitly, so I don't know what happens when you just use the member name. If you think it's wrong, I'd suggest opening a case with IBM.
          I did the following experiment. Created a physical source code file FILE in library LIB (this library is in the list of libraries of the job where the compilation will be performed). In this file I have created 2 HDR and SRC members. The HDR member filled in with the following code:
          Code:
          #include <stdio.h>
          The SRC member filled in with the following code:
          Code:
          #include "hdr"
          
          int main(int argc, char** argv) {
            printf("");
          }
          Then I compiled with the C compiler:
          Code:
          CRTBNDC PGM(LIB/SRC) SRCFILE(LIB/FILE) SRCMBR(SRC)
          In this case, the compilation was successful.
          After compiling with the C ++ compiler:
          Code:
          CRTBNDCPP PGM(LIB/SRC) SRCFILE(LIB/FILE) SRCMBR(SRC)
          Compilation failed. The error is as follows:
          Code:
          3 > CRTBNDCPP PGM(LIB/SRC) SRCFILE(LIB/FILE) SRCMBR(SRC)               
              "LIB/FILE(SRC)", line 1.10: CZP0836(30) The #include file "hdr" is not found.                                                                 
              The compilation failed.
          Thus, there is a C ++ preprocessor error. Can you tell me how to report this to IBM? Or, if it doesn't bother you, please do it yourself.

          Comment


          • #6
            Yes, I understand what you are saying. I always use ".h" on my #include statements, so I haven't run across the problem.

            I recommend opening a case with IBM. To do that:

            1) Visit http://www.ibm.com
            2) At the top of the page click Learn & Support
            3) From the menu that appears, click Open a case

            Comment


            • #7
              Scott, thanks for your help! Allow one more question.
              You say you always use ".h" in #include statements. This means that all included members are in a file named "H". When compiling, the library where this file is located is in the list of task libraries, or is it possible to specify the location of the file in the compilation command options?

              Comment

              Working...
              X