Like Tree5Likes

calling C functions from C++ code

This is a discussion on calling C functions from C++ code within the C++ Programming forums, part of the General Programming Boards category; My naive suggestion would be to create a new project with precompiled headers disabled, then put in the code that ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,749
    My naive suggestion would be to create a new project with precompiled headers disabled, then put in the code that you have written.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    You can disable precompiled headers for individual source files.
    Just select them and select properties, then find yourself into C/C++ and find that precompiled headers option and turn it off.
    iMalc likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    As I said, it's not really a choice because it's part of a larger project that uses the precompiled header. Some of the other code was written by somebody else.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Put your code into separate files and disable PCH for them.
    Alternatively, compile your C source files as C++.
    iMalc likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by Elysia View Post
    Put your code into separate files and disable PCH for them.
    Alternatively, compile your C source files as C++.
    The c code is in separage files, but same project. How do I disable PCH for individual files?

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Select only the C files, right-click and select properties.
    iMalc likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by Elysia View Post
    Select only the C files, right-click and select properties.
    I tried, but when properties comes up, there are only the following choices:

    Excluded from Build: (yes or no)
    Item Type:

    and the only category available is Configuration Properties, with subcategory General. Usually, to find the option to disable PCH, it's under a subcategory C/C++, which is not available unless I select the entire project. Am I missing something? Perhaps a specific Item Type?

  8. #23
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Nevermind, I did a bit more research and found out about the Yc[filename] option. Let me try it out. Thanks.

  9. #24
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Actually, that wasn't for what I thought it was. Yc[filename] is something else...

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    There should be a C/C++ category if you did it right.
    Select a source file, right-click, select properties. You did that on a specific file, did you not? Not the solution or anything else?
    For the record, /Yc and /Yu are used to use and create PCH; to not use them, you omit those options.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by Elysia View Post
    There should be a C/C++ category if you did it right.
    Select a source file, right-click, select properties. You did that on a specific file, did you not? Not the solution or anything else?
    For the record, /Yc and /Yu are used to use and create PCH; to not use them, you omit those options.
    Yes, I saw that about Yc and Yu. I finally figured out that there's no disabling pch option for .h files is what I was doing wrong. So I was able to disable it on the .c file. Now I get new errors, all of them syntax errors of the type:

    Code:
    cmath(19): error C2061: syntax error : identifier 'acosf'
    My c code uses math.h, but not cmath. I'll play around with this for a bit and see if I can get it to work. Thanks.

  12. #27
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    Found out about the relationship between cmath and math.h (they are basically, in a way, the same. No such thing as cmath.h)

    This raises many questions about why I am getting all those syntax errors in cmath...

  13. #28
    Registered User
    Join Date
    May 2010
    Posts
    2,760
    If you try to include the cmath header in a C file you will probably get quite a few errors. The cmath header file is not the same as math.h. The cmath header file probably includes some overloaded functions that are only available for use in C++. For example my cmath header file has several different abs() functions, one for double, one for float, and one for long doubles. Since C does not allow overloaded functions you would get several errors because of this. Also cmath includes a namespace declaration, and C does not use namespaces, another error.

    So you should always use the proper C standard header for a C file, and the proper C++ standard header for a C++ file.

    Jim
    Last edited by jimblumberg; 02-16-2012 at 10:30 PM.
    laserlight likes this.

  14. #29
    Registered User
    Join Date
    Oct 2011
    Posts
    29
    That makes perfect sense. I realized I was including iostream, which is a c++ library. That took away the cmath errors. Now I'm getting other errors, but they're with a different library I'm working with, so it's another story...

  15. #30
    Registered User
    Join Date
    May 2010
    Posts
    2,760
    Where did you find "your" C code? Are there other files or functions that came with "your" C code? "Your" C code looks to me like it may be part of a larger code base meant to be used as a library, not necessarily a stand alone function.

    Jim

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling functions
    By cda67 in forum C Programming
    Replies: 2
    Last Post: 10-14-2011, 11:56 PM
  2. Help calling and using a functions
    By method in forum Windows Programming
    Replies: 0
    Last Post: 07-08-2006, 04:08 PM
  3. calling functions & assembly code
    By Micko in forum C++ Programming
    Replies: 1
    Last Post: 02-25-2004, 02:27 PM
  4. calling functions::
    By Yoshi in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2002, 01:34 PM
  5. Functions calling themselves...?
    By mikebrewsj in forum C++ Programming
    Replies: 10
    Last Post: 01-17-2002, 11:09 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21