C Preprocessor `#define` works on my local machine but failed in GitHub Actions despite being on the same architecture [closed]

C preprocessing defines are hard to guarantee its ‘portability’? I think its my skills issue.

In vector.h, I use a token VECTOR_H_i_TYPE, which is NOT explicitly defined in vector.h. It is to represent any type that is going be decided by the client.

In other words, the intention is to have the client first define the macro, then include the header file; e.g.

#define VECTOR_H_i_TYPE uint16_t
#include "vector.h"

This is so that token pasting will allow it to be defined by the client and after the #include the type will be defined.

In vector.h, I also have the following macros.

#define PRINT_ANY(type) PRINT_FUNCTION_TYPE(type)

#define PRINT_FUNCTION_TYPE(type) print_ ##type

The intention is to let client define how to print VECTOR_H_i_TYPE by defining print_<VECTOR_H_i_TYPE> like so:

In client.c:

void print_uint16_t(uint16_t elem) { ... };

In vector.h, PRINT_ANY is used like so:

void vector_print(Vector* self) {
    ... // for loop on each elem in self
    PRINT_ANY(VECTOR_H_i_TYPE)(elem); // this should expand to `print_uint16_t(elem);`
};

On my local machine it works as intended!

On the CI with github actions it doesn’t! it says print_uint16_t is defined twice!

Here is the full error trace:

/home/runner/work/yet-another-c-template/yet-another-c-template/test/source/test_vector.c:10:6: error: conflicting types for 'print_uint16_t'
void print_uint16_t(uint16_t elem)
     ^
/home/runner/work/yet-another-c-template/yet-another-c-template/include/vector/vector.h:154:5: note: previous implicit declaration is here
    PRINT_ANY(VECTOR_H_i_TYPE)
    ^
/home/runner/work/yet-another-c-template/yet-another-c-template/include/vector/vector.h:70:27: note: expanded from macro 'PRINT_ANY'
#  define PRINT_ANY(TYPE) PRINT_FUNCTION_NAME(TYPE)
                          ^
/home/runner/work/yet-another-c-template/yet-another-c-template/include/vector/vector.h:78:37: note: expanded from macro 'PRINT_FUNCTION_NAME'
#  define PRINT_FUNCTION_NAME(TYPE) print_##TYPE
                                    ^
<scratch space>:33:1: note: expanded from here
print_uint16_t

The trace seems to suggest that the expansion of PRINT_FUNCTION_NAME(TYPE macro conflicts with the definition of void print_uint16_t(uint_16 *elem) in client.c.

The actual repository where these codes reside are in here: https://github.com/jymchng/yet-another-c-template

9

it says print_uint16_t is defined twice!

No, it doesn’t. At least, the diagnostics presented in the question do not say that. They say that there are conflicting declarations, one of them an implicit one. That there is a call relying on an implicit declaration of the function at all is a problem: that hasn’t been well-defined since C99, though many compilers continue to allow it for backwards compatibility. You can find all sorts of relevant information here on SO and elsewhere by searching for “implicit function declaration”.

If you are using any kind of decent compiler locally, then you can probably get it to emit analogous errors. With GCC, for example, you should (always) compile with -Wall, and you can convert any resulting warnings into errors by adding -Werror, too. That should get you the same error you present in the question.

It looks like the implicit declaration is coming from the call in the body of function void vector_print, defined in the header. As I already remarked in comments, external functions should not be defined in headers. That you do so is a contributing factor to the error, but the essential issue is that there is no declaration of print_uint16_t in scope at the point of that call. If you want to persist with this ill-considered approach, then you need to declare the function prior to the first call to it (preferably with a prototype).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật