Macros – Solution: The clang preprocessor concatenates an extra space compared to standard gcc – C99

I maintain a C library project on gcc and clang.

I'm looking for advice on how to make the following macros more portable, concise, readable, or standards-compliant.

When I compile

#define STRINGIFY(arg) STRINGIFY_(arg)
#define STRINGIFY_(arg) #arg

#define VERSION 1.01
#define PROJECT myProject
#define SUB_PROJECT mySub
#define DASH -


I receive

Clang 6.0.0 standard C99

myProject - mySub - 1.01.c

gcc 7.4.0 standard C99


I came up with the following solution

#define STRINGIFY(arg) STRINGIFY_(arg)
#define STRINGIFY_(arg) #arg
#define ID(arg) arg

#define VERSION 1.01
#define PROJECT myProject
#define LIB myLib
#define DASH -
#define DOTC .c

#define FILEVERSION(a, b, c, d, e) STRINGIFY(ID(a)ID(b)ID(c)ID(d)ID(e)ID(DOTC))


c99 – How to initialize a character[] with a string in C?

I have a union of tables of characters, bytes, words and long words that I have to initialize selectively.
I realized that I could not use more than one union member for booting. All arrays must be initialized via the byte array, even if the initial values ​​are 16-bit or 32-bit.
(that is to say instead of

array_words(0) = 0x1234
I need to do:
array_bytes(0) = 0x12;
array_bytes(1) = 0x34; // etc

No matter what I try to fail unless I do the following:

array_chars(0) = 'H',
array_chars(1) = 'e',
array_chars(2) = 'l', // etc.

The question: Can I somehow initialize a range of characters with a string or sequence of characters like this?

array_chars(0 ... 6) = { "Hello" };

or even

array_chars(0 ... 6) = { 'H', 'e', 'l', 'l', 'o', '' };

How to make a pre C ++ wrapper 11 of a POD structure made in C99?

Very good. First, the question may not be in the correct format. I will modify it as I add more information or the comments show a lack of information or structure.

I have a structure made of POD, in C99.

I will give an example of the type of structure in which I usually find the one that interests me (kindly extract Freetype 2.4.4):

        typedef enum BDF_PropertyType_

} BDF_PropertyType;
typedef struct BDF_PropertyRec_
Type BDF_PropertyType;
union {
const char * atom;
FT_Int32 integer;
Cardinal FT_UInt32;

} u;

} BDF_PropertyRec;

My question is: How to get a wrapper in C ++ 98 to interconnected structures?

I planned to do a course that used a BDF_PropertyRecbut using it as a private object and using it, but I still depend on malloc and free for its life cycle, quickly abandoning the idea by keeping in mind the two objects, as they do here: -into-C -class /

Here,, apply a form of the inheritance type to get a wrapper. I do not see how to achieve this with POD structures or classical data that have pointers connected to other structures, or a vector of these elements given by the base pointer and the maximum length, something like this:

typedef struct t_Elements_used
uint8_t value1;
uint16_t value2;
uint8_t value3;
uint32_t value4;
} * Elements_used; // Look at the pointer element, here it is cheating!

typedef struct t_Structura_POD_con_vectores
uint32_t elements;
Vector elements used; // It's cheating, read the definition of the previous typedef well!

} Structure_POD_with_vectors; // <How to integrate this in a class?

In software engineering (, they comment with the help of facades or std :: make_unique. In the case of C ++ 98, std :: make_unique it does not work (you have to insert the extension TR1 or use boost, and for the moment, it is not viable), and a facade pattern adds too many layers to access the elements of this vector, which makes the difficult encapsulation (one layer for the first structure, another for the second and one for the communication between the two, leaving the original structure duplicated, but I do not see that it is accessible without copies.

As I read in Coding Standards C ++ – 101 Rules, Guidelines and Best Practices, from Herb Sutter and Andrei Alexandrescu, recommends the use of RAII (Recommendation 13), which involves duplicating and to maintain the two objects, the structure and the object. C ++ converted.

I repeat the question: How to create a wrapper in C ++ 98 (obsolete!) For a structure connected to others in C99?