gcc

Why do debug symbols so adversely affect the performance of threaded applications on Linux?

Hi. I'm writing a ray tracer. Recently, I added threading to the program to exploit the additional cores on my i5 Quad Core. In a weird turn of events the debug version of the application is now running slower, but the optimized build is running faster than before I added threading. I'm passing the "-g -pg" flags to gcc for the debug...

Constant embedded for loop condition optimization in C++ with gcc

Will a compiler optimize tihs: bool someCondition = someVeryTimeConsumingTask(/* ... */); for (int i=0; i<HUGE_INNER_LOOP; ++i) { if (someCondition) doCondition(i); else bacon(i); } into: bool someCondition = someVeryTimeConsumingTask(/* ... */); if (someCondition) for (int i=0; i<HUGE_INNER_LOOP; ++i) ...

When compiling,I write " gcc -g -Wall dene2 dene2.c", then gcc emits some trace

When I compile my code,I write gcc -g -Wall dene2 dene2.c in the console. Then gcc emits some text on the screen. I don't understand what this output means (I couldn't think of a meaningful title for that reason, sorry). I have tried Google searching but haven't had any luck. I'm not asking for a detailed examination of all of the outp...

compile with -ansi -pedantic -Wall switches automatically with gcc

We are required to compile C source codes using gcc in this manner: gcc -ansi -pedantic -Wall program.c I'm wondering how can I 'automate' this so when I enter: gcc program.c It will automatically compile with the 3 switches. Is this possible? ...

reverse a linked list?

Hi there, Im trying to reverse the order of the following linked list, I've done so, But the reversed list does not seem to print out. Where have I gone wrong? //reverse the linked list #include <iostream> using namespace std; struct node{ int number; node *next; }; node *A; void addNode(nod...

-Wextra how useful is it really?

I'm reading the gcc manual at the moment, especially the part about warning/error flags. After reading the part about the -Wextra flag, I wonder if it is useful at all. It seems that it complains about things which seem to be rather subjective or a matter of taste. I'm not that experienced with gcc, I only use it from time to time for so...

XCode GCC-4.0 vs 4.2

I have just changed a compiler option from 4.0 to 4.2. Now I get an error: jump to case label crosses initialization of 'const char* selectorName' It works fine in 4.0 Any ideas? ...

GNU Make - Dependencies on non program code

A requirement for a program I am writing is that it must be able to trust a configuration file. To accomplish this, I am using several kinds of hashing algorithms to generate a hash of the file at compile time, this produces a header with the hashes as constants. Dependencies for this are pretty straight forward, my program depends on c...

gcc optimization? bug? and its practial implication to project

Hi All, My questions are divided into three parts Question 1 Consider the below code, #include <iostream> using namespace std; int main( int argc, char *argv[]) { const int v = 50; int i = 0X7FFFFFFF; cout<<(i + v)<<endl; if ( i + v < i ) { cout<<"Number is negative"<<endl; } else { ...

Objective-C++ visibility question

I have linked a library with my program. It works fine. The only problem is that there visibility errors/warnings (thousands of them). They are all of the form: newlib::method() has different visibility (default) in newlib.a and (hidden) in AppDelegate.o It is always with AppDelegate.o. I have tried to set the visibility for both the...

"Address of" (&) an array / address of being ignored be gcc?

Hi, I am a teaching assistant of a introductory programming course, and some students made this type of error: char name[20]; scanf("%s",&name); which is not surprising as they are learning... What is surprising is that, besides gcc warning, the code works (at least this part). I have been trying to understand and I wrote the followin...

x86 gcc assembly output help please

Pasted below is unoptimized GCC assembly output for "int main(){}". I'm relatively good with x86 assembly, but some of this is unfamiliar. Could someone please do a line-by-line walk-through of what's going on here? Thanks! .text .globl _main _main: LFB2: pushq %rbp LCFI0: movq %rsp, %rbp LCFI1: leave ret LFE...

What is a specifier-qualifier-list?

GCC likes to tell me that I'm missing a specifier-qualifier-list in its error messages. I know that this means I didn't put in a correct type of something. But what exactly is a specifier-qualifier-list? Edit: Example C code that causes this: #include <stdio.h> int main(int argc, char **argv) { struct { undefined_type *foo; } b...

Ofstream writes empty file on linux

Hi, I have a program which writes its output using ofstream. Everything works perfectly fine on Windows when compiled with Visual Studio, but it only writes empty file on Linux when compiled with GCC. ofstream out(path_out_cstr, ofstream::out); if(out.bad()){ cout << "Could not write the file" << flush; } else{ cout << "writing"; ou...

How do I activate #pragma pack on ubuntu 10.4 gcc 4.4.3

I am trying to activate #pragma pack(push, 8) on ubuntu 10.4 (8.10 would also be nice), which uses gcc 4.4.3, but I can't get it to work. Is there something more that need to be done? There is not even a warning if I compile with -Wunknown-pragmas so gcc seems at least to acknowledge it as a known pragma. It would be nice to use the pa...

Is this usage of test_and_set thread safe?

I've been thinking of how to implement a lock-free singly linked list. And to be honest, I don't see many bullet proof ways to do it. Even the more robust ways out there that use CAS end up having some degree of the ABA problem. So I got to thinking. Wouldn't a partially lock-free system be better than always using locks? May some oper...

Returning structs in registers - ARM ABI in GCC

Hi, In the ARM ABI documentation I come across functions defined like: __value_in_regs struct bar foo(int a, int b) { ... } but GCC(4.3.3) doesn't allow it and all I could find are references to some RealView compiler. Is there any way of doing this from GCC? I have tried -freg-struct-return but it doesn't make a difference. As ...

Compatible types and structures in C

I have the following code: int main(void) { struct { int x; } a, b; struct { int x; } c; struct { int x; } *p; b = a; /* OK */ c = a; /* Doesn't work */ p = &a; /* Doesn't work */ return 0; } which fails to compile under GCC (3.4.6), with the following error: test.c:8: error: incompatible types in a...

What does the -all_load linker flag do?

I can't find anywhere what the -all_load flag do when compiling Objective-C code. I have some issues uploading binaries to Apple, the they say it's because I didn't use this flag, but my code compiles even without it. Can some one help me with that? Thanks ...

How do I exclude stuff from gprof output?

I'm trying to profile an application I have, but I don't want anything related to the UI (made in wxWidgets) to show up in gprof's callgraph etc. How can I do this? ...