gcc

Downcasting shared_ptr<Base> to shared_ptr<Derived>?

Update: the shared_ptr in this example is like the one in Boost, but it doesn't support shared_polymorphic_downcast (or dynamic_pointer_cast or static_pointer_cast for that matter)! I'm trying to initialize a shared pointer to a derived class without losing the reference count: struct Base { }; struct Derived : public Base { }; shared_...

Inline assembly error, thwarting gcc compilation attempts.

Greetings, SO. I have some code which I've made attempts at compiling using gcc, but my attempts have been thwarted. Could anyone more versed assist me with the subject, perhaps there's something I'm missing. I'm compiling this code on Linux Kitchen 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linux. int ...

How to type cast a literal in C

Hi, I have a small sample function: #define VALUE 0 int test(unsigned char x) { if (x>=VALUE) return 0; else return 1; } My compiler warns me that the comparison (x>=VALUE) is true in all cases, which is right, because x is an unsigned character and VALUE is defined with the value 0. So I changed my code to: if ( ((sign...

installing gcc on vista

I downloaded gcc 4.4.0 and unzipped it to C:\Program Files\gcc forgive me for being a novice, but...now what? I read the install readme file but it's over my head. how do i get it to work? ...

optimization in gcc

Hi, I have two questions: (1) I learned somewhere that -O3 is not recommended with gcc, because The -O3 optimization level may increase the speed of the resulting executable, but can also increase its size. Under some circumstances where these optimizations are not favorable, this option might actually make a program slower. in fa...

compiling 64 bit linux kernel with gcc

While trying to compile a 64 bit linux kernel using gcc, I see the following error : kernel/bounds.c:1: error: code model ‘kernel’ not supported in the 32 bit mode kernel/bounds.c:1: sorry, unimplemented: 64-bit mode not compiled in This is what gcc -v reports : Using built-in specs. Target: i586-redhat-linux Configured with: ../conf...

Explanation of Asm code

Hi, The following GCC inline asm is taken from LuaJit's coco library. Can someone provide a line by line explanation of what it does? static inline void coco_switch(coco_ctx from, coco_ctx to) { __asm__ __volatile__ ( "movl $1f, (%0)\n\t" "movl %%esp, 4(%0)\n\t" "movl %%ebp, 8(%0)\n\t" "movl 8(%1), %%ebp\n\t" "...

What are the known C/C++ optimizations for GCC

I am have a lot of code that I need to optimize and make it run faster. I used opreport to tell me where the code spends a lot of time. I use the following command to get the statistics opreport -g -l -d Suggestions to get better statistics are appreciated using different flags, perhaps find it per line number instead of function numb...

Switching callstack for C++ functions

Hi, Here's my previous question about switching C callstacks. However, C++ uses a different calling convention (thiscall) and may require some different asm code. Can someone explain the differences and point to or supply some code snippets that switch C++ callstacks (preferably in GCC inline asm)? Thanks, James ...

How can I find the calling routine for a symbol in case of a linker error "undefined reference"?

Hello, I have a problem linking an application for an embedded target. I'm developing on a windows box using Min-GW for an ARM9 target that runs under Linux. Actually I'm switching from static linking to dynamic linking with .so-libraries to save memory space. I get the error message libT3Printer.so: undefined reference to `__ASSERT' ...

C++: Safe to use longjmp and setjmp?

Hi, Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following? Exception handling (I'm not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling) *this pointer Signals Smart pointers (boost's shared and intrusive point...

SetJmp/LongJmp: Why is this throwing a segfault?

Hi, The following code summarizes the problem I have at the moment. My current execution flow is as follows and a I'm running in GCC 4.3. jmp_buf a_buf; jmp_buf b_buf; void b_helper() { printf("entering b_helper"); if(setjmp(b_buf) == 0) { printf("longjmping to a_buf"); longjmp(a_buf, 1); } printf("return...

C++: Optimize using templates variables

Hi, Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter = true) { if(tryUseGetter) { if(_properties[name]->hasGetter) { return (Type*)_properties[name]->getter(); } return (Type*)_properties[name]->data; } else { return (Type*)_properties[name]->data; } } ...

improving gcc build times

I'm trying to improve the D front-end for GCC(GDC). I just got the d front-end compiling with GCC-4.3.1. But it took an awful long time compared to build it when I used GCC-4.1.2. This is the version of gdc: Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../configure --enable-languages=d --prefix=/usr/local/gdc --e...

C++: Force Preprocessor to use a previous definition in a redefinition

Update 3: Never mind. I kinda got what I was looking for. The following gives unique identifiers inside a class. static const int _counter_start = __COUNTER__; static const int val1 = __COUNTER__ - _counter_start; static const int val2 = __COUNTER__ - _counter_start; Update 2: Boost Preprocessor I will be implementing something ak...

Null or terminator canary

Can I force the gcc to use a null canary or terminator canary, when SSP is enabled, instead of random canary? If so, how? ...

C++ Class instance array initalization

Hi, I have a class A as follows: class A { public: A() { printf("A constructed\n"); } ~A(); //no other constructors/assignment operators } I have the following elsewhere A * _a; I initalize it with: int count = ... ... _a = new A[count]; and I access it with int key = .... ....

Getting started with SSE

Hello, I want to learn more about using the SSE. What ways are there to learn, besides the obvious reading the Intel® 64 and IA-32 Architectures Software Developer's Manuals ? Mainly I'm interested to work with the GCC X86 Built-in Functions. ...

Assembly Function to C Program without Parameter Passing or Return Value

I need to create an assembly function that adds two positive numbers together, called by a C program. The C program would look like this: #include <stdio.h> int main(void){ int a = 0; int b = 0; int c = 0; printf( "Enter first number: " ); scanf( "%d", &a ); printf( "Enter second number: " ); scanf( "%d", &b ); sum(); printf( "Answer ...

"expected ')' before '*' token" - On linux but not on Windows.

Need help compiling in C. When using GCC at home (Windows, 3.4.5), the code compiles fine (even with -Wall). When using the uni's GCC (4.3.3, debian), I keep getting the following message - "expected ')' before '*' token". What might be the matter? (Needless to say, compiling it on school's farm is a must). The exact error message: Matr...