gcc

delete this pointer behaviour in g++

#include <stdio.h> class Foo { public: Foo(char x); Foo(char x, int y); ~Foo(); void abc(); void dev(); }; void Foo::dev() { printf("inside dev \n"); } void Foo::abc() { printf("inside abc \n"); delete this; dev()...

Under what circumstances can a vtable pointer be null (or 0x1)?

I am currently debugging a crashlog. The crash occurs because the vtable pointer of a (c++-) object is 0x1, while the rest of the object seems to be ok as far as I can tell from the crashlog. The program crashes when it tries to call a virtual method. My question: Under what circumstances can a vtable pointer become null? Does operator...

iPhone -mthumb-interlinking

hi! os i figured out how to use the -mthumb and -mno-thumb compiler flag and more or less understand what it's doing. But what is the -mthumb-interlinking flag doing? when is it needed, and is it set for the whole project if i set 'compile for thumb' in my project settings? thanks for the info! ...

More information on `({});` in C?

I've noticed that sometimes, C macros are written as something like this: #define foo(bar) ({ ++bar; }) After some experimentation, I've found that: ({}); will compile, but do nothing. (As expected.) Leaving the ; off will cause a syntax error. A side effect of this is ensuring that foo() looks like a function in your code. (Althoug...

Can I legally incorporate GPL software in a proprietary, closed-source Web app?

I am developing a close source Web-based C IDE which uses gcc compiler for compiling the code on the server. You can think of it as something like Google Doc where you write C source and can see the console output in a separate window. I want to use a monthly subscription model for my website, where users pay a monthly fee to use the sof...

Undefined reference to non-member function - C++

I have the following in header file. namespace silc{ class pattern_token_map { /* Contents */ }; pattern_token_map* load_from_file(const char*); } In the CPP file (this has got proper includes) pattern_token_map* load_from_file(const char* filename) { // Implementation goes here } In another CPP file. This has...

Compile string of C code

Really off the wall question here, but is there a way to compile a string of C code in GCC without any medium to hold that string (eg. a source file)? Something along the lines of: $ gcc "#include <stdio.h> int main( void ){ printf('hello world'); return 0;}" -o test Feels really dirty, but it would be really nice if there was some s...

Arithmetic operations on unsigned and signed integers

See this code snippet int main() { unsigned int a = 1000; int b = -1; if (a>b) printf("A is BIG! %d\n", a-b); else printf("a is SMALL! %d\n", a-b); return 0; } This gives the output: a is SMALL: 1001 I don't understand what's happening here. How does the > operator work here? Why is "a" smaller than "b"? If it is indeed sma...

cmake & gcc compiles every file every time

Hi folks, I'm a learning c++ developer writing a game initially on the Mac platform using XCode, but now moving to cross platform by leveraging CMake. So far I can get it compiled on my ickle linux netbook and I'm putting together a dev environment on this machine for on the go coding. However I'm finding that gcc recompiles every file w...

Calling MATLAB from C

I'm writing a Java application that needs to be able to run MATLAB commands. To do so, I'm using a C program that the Java application can call upon to interface with MATLAB. However, even after researching the MATLAB engine, I can't seem to figure out how to compile the C program. This documentation seems to be compiling the C program f...

Using DirectX headers from Wine to compile under MingW

I have been attempting to build HLSL shader support into VLC player. I have hit a brick wall due to lack of utility methods in d3d9.h in MingW to load a .fx file and compile the shader. So under advise from VLC developers I borrowed the DX9 headers from Wine. Now with the d3dx9.h include enabled I have lots of compiler errors in the for...

GCC internals: Where are fake dereferences removed?

The expression &ptr->fld doesn't represent a dereference, instead it should be treated as (uint32_t)ptr + offsetof (ptr, fld). I am certain that GCC does this simplification, but I cannot find where in the code. The above ends up as ADDR_EXPR(COMPONENT_REF (INDIRECT_REF (ptr), fld)) in the AST, but at some point it should go through an...

Stripping linux shared libraries

We've recently been asked to ship a Linux version of one of our libraries, previously we've developed under Linux and shipped for Windows where deploying libraries is generally a lot easier. The problem we've hit upon is in stripping the exported symbols down to only those in the exposed interface. There are three good reasons for wantin...

C++ syntax to call templated inner class static member function?

I have some template code which compiles fine in VC9 (Microsoft Visual C++ 2008) but won't compile in GCC 4.2 (on Mac). I'm wondering if there's some syntactical magic that I'm missing. Below I have a stripped-down example which demonstrates my error. Sorry if this example seems meaningless, I removed as much as I could to isolate thi...

GCC option to get statvfs64

Hi, I am using statvfs function call on AIX. And using GCC compiler. I would like statvfs call to resolve to statvfs64 by preprocessor. Ex: In Solaris, using "-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" flags with gcc i am resolved to statvfs64. Could you please help in getting the similar flags on AIX which resolves me to statvfs64...

Better C++ syntax for template base class typedefs and functions?

I have code that compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 (on Mac, if that matters). If I pile on enough qualifiers and keywords I can force it to work in GCC but this doesn't seem right. Here's a minimal code sample exhibiting my problems: template< typename N > struct B { typedef N n_type; ...

C++ syntax for explicit specialization of a template function in a template class?

I have code which works in VC9 (Microsoft Visual C++ 2008 SP1) but not in GCC 4.2 (on Mac): struct tag {}; template< typename T > struct C { template< typename Tag > void f( T ); // declaration only template<> inline void f< tag >( T ) {} // ERROR: explicit specialization in }; ...

Are Multiline macros in GCC supported.

Hello, Are multi-line macros supported(compilable) in gcc version 3.2.4. I am trying to build my source which has multi-line macros on a linux host using above mentioned gcc version. I get compilation error at the macro, which is multiline. #define YYCOPY(To, From, Count) \ do \ { ...

Referencing libraries for a Linux executable

I have written an application in Java and succesfully compiled it using gcj. It worked surprisingly well, but I've run into a hurdle: I can only run the executable through a shell script, because I have to specify the library paths. The libraries I need are SWT, Xerces and GNU-crypto. Is there a way to statically link the libraries whe...

Using a .lib built with Visual Studio in Eclipse/CDT/gcc

Hello everyone I am having some trouble compiling a programm with gcc on windows which was initially developed with Visual Studio. So far I was able to resolve almost all problems like missing header files and such, but now I am stuck at one last thing: gcc fails to link to one of the third party libs my program uses (FlyCapture2.lib). ...