Re: Need help in Including/converting C files in C++ project

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks for your reply. I never realized that I should set the "Compile As"
setting to "default.(That's strange indeed. Juat as what I said, I did
change this one to "C" before.)

At last I can get it to work...

"John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
???????:uVGfJVhUFHA.548@xxxxxxxxxxxxxxxxxxxxxxx
> "Lau Lei Cheong" <leu_lc@xxxxxxxxxxxx> wrote in message
> news:u6k6TUfUFHA.3624@xxxxxxxxxxxxxxxxxxxx
>> Hello,
>>
>> I've a few C files in hand containing functions that can be used to
>> convert a string into MD5 hash string. When I tried to include the c
>> sources and header files to the project, a lot of errors and warnings
>> comes out.
>> The c files can be compiled and run successfully when placed in a
>> standalone project. (with "Project Properties"->"Advanced"->"Compile
>> to" set to "C executables" of course, and compile option "-DMD=5" to
>> specify the MD marco)
>> So I think the sources are Okay.
>>
>> Would anyone please give me a pointer on how to "include the files
>> in C++ project"/"convert these C files to C++ sources"?
>
> You could just leave them as .c files. A single project can compile both
> .cpp and .c files, treating them differently based on the extension.
> Change the "Advanced->Compile As" setting to default.
>
> If you wish to get the .c files to compile as .cpp files, then the
> compiler error messages should tell you most of what needs to be done. In
> my experience it mainly involves adding casts (especially if you are using
> a lot of void* pointers). A complete list of differences between C and C++
> is given in Appendix B of Stroustrup's The C++ Programming Language. Some
> highlights:
>
> 1. C++ requires that function prototypes be declared before a function is
> called.
> 2. An empty argument list in a C++ prototype means that the function takes
> no arguments, whereas in C it means that the number and type of arguments
> are unspecified.
> 3. C++ doesn't allow "old-style" function definitions in which the types
> of function parameters are specified after the closing parenthesis.
> 4. If a type is omitted from a declaration, C defaults to int. C++ gives
> an error.
> 5. C++ doesn't allow integers to be assigned to enum types without a cast.
> 6. C++ provides many new keywords that might clash with variable names in
> a C file.
> 7. const variables in C++ must be initialised when first declared. They
> have internal linkage in C++ unless prefaced with extern.
> 8. The following is legal C but not legal C++
>
> struct X
> {int a;};
>
> struct Y
> {int b;};
>
> typedef struct Y X;
>
> This is because the name of the first struct is struct X in C, which
> differs from X in the typedef. The name of the first struct is X in C++,
> which is the same as the X in the typedef. (You can also use struct X as
> the name in C++, but the possibility of using just X is what matters for
> present purposes.)
>
>
>> A second question is: If I included the files, would it be right
>> to just specify the "-DMD=5" in the project properties, or I should
>> specify it elsewhere?
>
> That depends on whether you want the macro #defined in all your files.
> --
> John Carson


.



Relevant Pages

  • Re: associative array, container, mapping, terminology
    ... |> is a pointer, I see that as a kind of type, but also specific to what it ... |> different kind of struct I consider to really be two different types. ... | but which kind isn't known at compile time, ... I'm looking at having a mapping that is homogenous keys and homogenous data, ...
    (comp.programming)
  • Re: Generating a simple hand-coded like recursive descent parser
    ... include compound words due to intrinsic functions. ... What do you mean by keyword combinations? ... "compile", directive on what compiler options will be used ... struct ASTNode { ...
    (comp.compilers)
  • Re: curiously recurring template pattern problem
    ... > struct X ... > typedef int type; ... > type is not allowed' pointing at the typedef in X. ... > this kind of construct is difficult or impossible to compile for some ...
    (comp.lang.cpp)
  • Re: ANSI C Compilation linking problem
    ... I have the files group.h and group.c that use a struct define in logic.h and two fonctions define in logic.c. ... when the program compile, it is able to find the reference to the ... So the logic.o wasnt really compile and he forgot that it wasnt complete and still tryed to link it. ...
    (comp.lang.c)
  • Templates with constant array parameter
    ... How do I parameterize a template by a a allocated array of integers, ... which is declared static and constant, so I can make compile time ... struct IF{ ... static void exec { ...
    (comp.lang.cpp)