Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 197 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C vs C++ compilation incompatibility - does not name a type

#1
I am trying to use a supplier's library in combination with my C++ application. The library is largely based on C, which is normally not a problem with the `extern "C"` option, but I ran into an issue that the C++ compiler does not accept.

I simplified my code into the following example files. header.h represents a header from the suppier library, main.c/cpp are my own files. My real application is a C++ application, so I want to get it to work with main.cpp.

header.h (note the line `u64 u64;`):

#ifndef HEADER_H
#define HEADER_H

#include <stdint.h>

typedef uint64_t u64;

union teststruct {
u64 u64;
struct {
u64 x:32;
u64 y:32;
} s;
};

#endif

main.c:

#include <stdio.h>
#include "header.h"

int main() {
union teststruct a;
a.u64=5;
printf("%x\n", a.u64);

return 0;
}

main.cpp (same as main.c but with an extra `extern "C"` statement):

#include <stdio.h>

extern "C" {
#include "header.h"
}

int main() {
union teststruct a;
a.u64=5;
printf("%x\n", a.u64);

return 0;
}

Compiling main.c using the line

gcc -o test main.c

compiles without problems. However, compiling the C++ version using the g++ compiler with the command

g++ -o test main.cpp

gives the following compiler errors:

In file included from main.cpp:12:0:
header.h:11:9: error: ‘u64’ does not name a type
u64 x:32;
^
header.h:12:9: error: ‘u64’ does not name a type
u64 y:32;
^

The issue is that the supplier used the same name (u64) for both the type and the variable name, which seems like a bad idea to begin with, but gcc apparently accepts it. I do not want to change the library (i.e. header.h) as it is very large,this occurs a lot in the code, and I occasionally get updates for it. Is there a way to make g++ accept this combination, or a way to modify main.cpp to make it compile _without_ changing header.h?
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through