Do you have any horror stories to tell? The GCC Manual recently added a warning regarding -fstrict-aliasing and casting a pointer through a union:
[...] Taking the address, casting the resulting pointer and dereferencing the result has undefined behavior [emphasis added], even if the cast uses a union type, e.g.:
union a_union...
I've noticed a difference in behaviour for gcc's destructor when compiled under linux and crosscompiled with mingw.
On linux the destructor will not get called unless the program terminates normally by itself (returns from main). I guess that kind of makes sense if you take signal handlers into account.
On Win32 however, the destructor...
What I want to do is this:
#include <memory>
class autostr : public std::auto_ptr<char>
{
public:
autostr(char *a) : std::auto_ptr<char>(a) {}
autostr(autostr &a) : std::auto_ptr<char>(a) {}
// define a bunch of string utils here...
};
autostr test(char a)
{
return autostr(new char(a));
}
void main(int args, char **ar...
I have inherited a very long set of macros from some C algorithm code.They basically call free on a number of structures as the function exits either abnormally or normally. I would like to replace these with something more debuggable and readable. A snippet is shown below
#define FREE_ALL_VECS {FREE_VEC_COND(kernel);FREE_VEC_COND(cirra...
I needed to include a few c headers ( non standard header files ) in my C++ code to be compiled by gcc. The C header (foo.h) has support for :
#ifdef __cplusplus
extern "C" {
#endif
and similarly at the end for }. The c++ code has the include "foo.h"
I believe I should be able to just include the header (foo.h) and create instan...
I suspect I am doing something dumb here but I am getting seg faults on an embedded Linux platform (GCC compiler) when I try to run pthread_rwlock_init() on a rwlock embedded in a structure.
struct rwlock_flag {
int flag; // Flag
pthread_rwlock_t * rwlock; // Reader/writer lock for flag
};
The following causes a seg...
I have one shared object (a.so) which has statically linked (s.so). b.so also has a static link of s.so.
a.so does a dlopen on b.so , will "s.so" code be shared between the two?
The .so are built on gcc 4.1 on RedHat linux.
The s.so is compiled against a.so and b.so with -Bstatic and --no-whole-archive option.
...
I get the following errors:
error: missing terminating " character
and
error: stray `\' in program
In this line of C code:
system("sqlite3 -html /home/user/.rtcom-eventlogger/el.db \"SELECT service_id, event_type_id,free_text, remote_uid FROM Events WHERE remote_uid=\'%d\' ORDER BY start_time DESC;\" > lol.html", nr);
"nr" is a...
I have the following function from some legacy code that I am maintaining.
long getMaxStart(long start, long count, const myStruct *s1, ...)
{
long i1, maxstart;
myStruct *s2;
va_list marker;
maxstart = start;
/*BUGFIX: 003 */
/*(va_start(marker, count);*/
va_start(marker, s1);
for (i1 = 1; i1 <= count; i...
I am getting the following warning when compiling some legacy C code on Ubuntu Karmic, using gcc 4.4.1
The warning is:
src/filename.c:385: warning: '0' flag
ignored with precision and ‘%i’
gnu_printf format
The snippet which causes the warning to be emitted is:
char buffer[256] ;
long fnum ;
/* some initialization ...
Hi, how can I pass the option --enable-auto-import to ld from gcc?
...
Hi,
I know that nested functions are not part of the standard C, but since they're present in gcc (and the fact that gcc is the only compiler i care about), i tend to use them quite often.
Is this a bad thing ? If so, could you show me some nasty examples ?
What's the status of nested functions in gcc ? Are they going to be removed ?
...
I am compiling a program in which a header file is defined in multiple places. Contents of each of the header file is different, though the variable names are the same internal members within the structures are different .
Now at the linking time it is picking up from a library file which belongs to a different header not the one which ...
I have a static library that is compiled with gcc 3.4.2. I am building a shared library that relies on this static lib. I will be building this shared library (.so) with gcc 4.2.2. I was wondering what are the potential pitfalls of using the 3.4.2 static library in a gcc 4.2.2 shared library?
...
hi!
I have two precompiled library: X.a and Y.a and a test.cpp (without main function) source code use these two libraries.
I compiled the C++ using:
g++ -c test.cpp
and I got 'test.o'.
Now how can I link these three together to generate a .a file because test.cpp use some function in X.a and Y.a and other GCC libraries?
BTW, I am...
I'm trying to create a cmake equivalent to the following make:
demo: main.cpp
gcc -o demo main.cpp
./demo
demo is executed whenever demo is created.
This what I came to, but demo is not executed as I want:
add_executable(demo main.cpp)
add_custom_target(run_demo demo)
This is actually equivalent to:
all: demo
demo: main.cpp...
Is there a way to have gcc generate %pc relative addresses of constants? Even when the string appears in the text segment, arm-elf-gcc will generate a constant pointer to the data, load the address of the pointer via a %pc relative address and then dereference it. For a variety of reasons, I need to skip the middle step. As an example...
Hi there, I'm trying to sort names into alphabetical order inside a linked list but am getting a run time error. what have I done wrong here?
#include <iostream>
#include <string>
using namespace std;
struct node{
string name;
node *next;
};
node *A;
void addnode(node *&listpointer,string newname){
node *temp;
temp = ...
Is there a way to tell gcc to throw a SIGFPE or something similar in response to a calculation that results in NaN or (-)inf at runtime, like it would for a divide-by-zero?
I've tried the -fsignaling-nans flag, which doesn't seem to help.
...
On my Linux platform, I have several versions of gcc.
Under usr/bin I have:
gcc34
gcc44
gcc
Here are some outputs:
$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
$ gcc44 --version
gcc44 (GCC) 4.4.0 20090514 (Red Hat 4.4.0-6)
I need to use the 4.4 version of gcc however the default seems to the 4.1 one.
I there a wa...