Thread: Using GTest with C - _Generic preventing build?

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    1

    Using GTest with C - _Generic preventing build?

    Hello all,

    GTest is a C++ library, but can be used with C by using "extern" with header inclusions.

    However, _Generic in C does not exist in C++, and I am not able to build the project because of it. I am reading that Gtest only supports C to the extent that it can include the C headers, which apparently does not extend to _Generic.

    Is there a workaround, or am I forced to abandon GTest in favor of Unity?

    Thanks,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Generic selection - cppreference.com
    Suggests that in C++, you use templates.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    gtest is an unit testing framework also called googletest.

    It is for testing C++ code!

    It can test C code that can run as C++; but, in the 5 minutes looking I saw no where that said it can test C code that cannot be ran as C++.

    Please explain why you think gtest is a library?

    And, please understand you need to compile using an C++ compiler the gtest framework code. Your code might or might not be able to compile with an C Compiler. And, you need to make your headers C++ compiler compatible. In GCC, you likely will need to link the code using C++ and not the C linking compiler library/linking command.

    The above is based on only about 5 minutes research.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 01-19-2017, 11:05 PM
  2. preventing suspend
    By silentkarma in forum Windows Programming
    Replies: 16
    Last Post: 03-10-2008, 06:43 PM
  3. Preventing Cancel?
    By JoeCoder in forum Windows Programming
    Replies: 3
    Last Post: 01-18-2004, 03:16 PM
  4. Preventing Newline
    By subdene in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2002, 02:10 PM
  5. preventing piracy...
    By Sebastiani in forum C Programming
    Replies: 7
    Last Post: 03-15-2002, 10:06 PM

Tags for this Thread