Does the following program architecture make sense?

Discussion in 'C Programming' started by mikelinyoho, Dec 3, 2005.

  1. mikelinyoho

    mikelinyoho Guest

    #include <stdio.h>
    #include "test1.c"
    #include "sample.cpp"

    int main(void){
    output();
    output();

    testmain();


    getchar();
    return 0;

    }

    -------------------------------------
    #include"test1.c"
    #include"sample.cpp"

    include *.c and *.cpp at the same time?



    Thank You
    Best Regards
    mikelinyoho, Dec 3, 2005
    #1
    1. Advertising

  2. mikelinyoho wrote:
    > #include <stdio.h>
    > #include "test1.c"
    > #include "sample.cpp"
    >
    > int main(void){
    > output();
    > output();
    >
    > testmain();
    >
    >
    > getchar();
    > return 0;
    >
    > }
    >
    > -------------------------------------
    > #include"test1.c"
    > #include"sample.cpp"
    >
    > include *.c and *.cpp at the same time?


    it is very unusual to include a ".c" file. It is close to being a
    "never do this".
    If you want to call things in another ".c" file then link them together
    (see
    your compiler documentation).

    Does your program really contain both C and C++ code?


    --
    Nick Keighley
    Nick Keighley, Dec 3, 2005
    #2
    1. Advertising

  3. mikelinyoho

    santosh Guest

    mikelinyoho wrote:
    > #include <stdio.h>
    > #include "test1.c"
    > #include "sample.cpp"
    >
    > int main(void){
    > output();
    > output();
    >
    > testmain();
    >
    >
    > getchar();
    > return 0;
    >
    > }
    >
    > -------------------------------------
    > #include"test1.c"
    > #include"sample.cpp"
    >
    > include *.c and *.cpp at the same time?


    If you compile as a C++ program (using a C++ compiler) it may compile.
    A C only compiler (or one compiling as C) will reject the contents of
    the
    "sample.cpp" file, if they contain C++ code.

    Although 'include' files can have any suffix, their contents must be
    syntactically and semantically correct for the particular program in
    which they are included, under a particular compiler operating under
    particular switches. The programmer has to figure it out.
    santosh, Dec 3, 2005
    #3
  4. mikelinyoho

    Malcolm Guest

    "mikelinyoho" <> wrote
    > #include <stdio.h>
    > #include "test1.c"
    > #include "sample.cpp"
    >
    > int main(void){
    > output();
    > output();
    >
    > testmain();
    >
    >
    > getchar();
    > return 0;
    >
    > }
    >
    > -------------------------------------
    > #include"test1.c"
    > #include"sample.cpp"
    >
    > include *.c and *.cpp at the same time?
    >

    Yes.
    It is pretty horrible but programs can easily be written in C to compile as
    C++, and sometimes you might want to paste together a source file from
    multiple includes.
    (Normally you would just compile the source files separately and link, but
    if you are doing something messy and ugly with globals / statics there might
    be a reason for not doing so. As I said, it pretty horrible but not
    senseless).
    Malcolm, Dec 3, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    0
    Views:
    348
  2. mike
    Replies:
    0
    Views:
    367
  3. mike
    Replies:
    0
    Views:
    390
  4. mike
    Replies:
    1
    Views:
    310
    Harlan Messinger
    Apr 20, 2005
  5. mikelinyoho
    Replies:
    2
    Views:
    229
    Jonathan Mcdougall
    Dec 3, 2005
Loading...

Share This Page