Re: Need help in Including/converting C files in C++ project
- From: "Lau Lei Cheong" <leu_lc@xxxxxxxxxxxx>
- Date: Fri, 6 May 2005 18:43:17 +0800
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
.
- References:
- Need help in Including/converting C files in C++ project
- From: Lau Lei Cheong
- Re: Need help in Including/converting C files in C++ project
- From: John Carson
- Need help in Including/converting C files in C++ project
- Prev by Date: Re: string to int
- Next by Date: unused template class methods
- Previous by thread: Re: Need help in Including/converting C files in C++ project
- Next by thread: Re: How include animated GIF into CEdit ?
- Index(es):
Relevant Pages
|