gcc

Casting to void doesn't remove warn_unused_result error

In a test, I'm discarding anything from stderr since it clutters the output of the test case. I'm using the following code: freopen("/dev/null", "w", stderr); When compiling with -Wall -Werror, I get the error error: ignoring return value of ‘freopen’, declared with attribute warn_unused_result which is expected. However, the usual...

determine code size

I have library intended for embedded devices developed in C for which I need to compute the code size. The OS is Linux and compiler is gcc. Could you please indicate how this can be done? Also are there ways in which I can reduce the foot print size using mechanisms like compiler optimization? ...

Making gcc generate only machine code.

More specifically, I would like to produce a file that I can load into memory (for example with mmap) and then jump to the start of that memory to run the code. Ideally, I'd like the option of either making the code relocatable (which might be inefficient) or specifying an explicit address that the code expects to be loaded at (which is...

how to use struct in gcc?

I am of late working on gcc compiler. whenevr i m compiling my code, m encountering problem with declaration of structure. How to tackle this problem. Do i need to write the syntax differently in gcc?. if yes, how? please suggest something. ...

How can I compile C++ code using another C++ program?

I want to create a program that modifies another c++ source,compiles it and runs the exe. I mean with something like gcc may be I can but on a windows os gcc may not be present. Is it possible? ...

interpreting gcc map file

I need to find the code size for a library developed using C on linux. I have generated the map file using the gcc linker options against a sample application that uses this library. The map file is quite exhaustive. How do I find out the code size of the library from the map file? any pointers to any documentation on how to interpret t...

Problem Exporting C++ symbols

iam trying to export some C++ symbols from GTK webkit code with default flags -fvisibility=hidden and -fvisibility-inline-hidden Only the C apis seem to be exported and work: #define API __attribute__((visibility("default"))) class API export1 { public: void export1_f(); }; API void export2(); extern "C" API void export3(); Out...

std::random_shuffle, compliler error: no matching function for call [closed]

Hi! I cannot compile following code by g++ 4.3.2: #include <stdlib.h> #include <algorithm> struct Generator { ptrdiff_t operator() (ptrdiff_t max) { return rand() % max; } }; // ... Generator generator; std::vector<size_t> indices; // fill vector std::random_shuffle(indices.begin(), indices.end(), generator); // error here! ...

LLVM 2.0 can't build for iPhone simulator. GCC 4.2 works fine.

When I build my project (any project, really - I tried creating a new empty project with the same results), it builds fine with GCC 4.2 under either Xcode4 or Xcode 3.2.4. If I build using LLVM 2.0 under Xcode4 or with LLVM 1.5 under Xcode3, I get compile-time build failures, but only when building for the Simulator. The build errors...

Polymorphically catching an exception in a -fno-rtti shared library on Mac OS X

Hi, I'm building a shared library with f-no-rtti. Internally, this library throws std:invalid_argument and catches std::exception, but the catch clause is never entered. The following code reproduces the problem (g++ 4.2, Mac OS X 10.6): // library.cpp: exports f(), compiled with -fno-rtti #include <stdexcept> #include <iostream> exte...

what are all these features of gcc? (-l -a -etc)

Can someone tell me in plan and simple terms what some of the more important features and options are for gcc and what they do? I look at the man pages and my head feels like exploding lol. ...

Preventing terminal window from popping up when launching program

Hi. I am compiling this program on Windows, with gcc (MinGW) and GTK+: #include <gtk/gtk.h> void *destroy(GtkWidget *widget, gpointer data) { gtk_main_quit(); } int main(int argc, char *argv[]) { // Initalize GTK+ gtk_init(&argc, &argv); // Create GTK+ window GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL...

Best replacement for GCC #ident

I used to set this at top of my source files to be able to grep -a "ID :" on my binaries : #ident "\\n$@ ID : my_library.o v1.3 (25/08/07)@$\\n" However, this is deprecated in GCC 4.3.3. Any suggestions ? I came through __attributes__(section()), but not sure if this will get stripped, and anyway, I was guessing there was a...

iphone app run in the simulator but not on the device

Hi, I am trying to run the Facebook DemoApp on my iphone and I get the following errors (it works without errors on the simulator) Please help me ***************************** Build DemoApp of project DemoApp with configuration Debug Ld build/DemoApp.build/Debug-iphoneos/DemoApp.build/Objects-normal/armv6/DemoApp normal armv6 cd /U...

What is the meaning of this splint warning and what might I be doing wrong?

This is the line of code: bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[2]); Running splint 3.1.2 generates this warning: cpfs.h:21:74: Function parameter times declared as manifest array (size constant is meaningless) A formal parameter is declared as an array with size. The size of the...

How do I get full assembler output in gcc?

I know I can get the assembler source code generated by the compiler by using: gcc -S ... even though that annoyingly doesn't give me an object file as part of the process. But how can I get everything about the compiled code? I mean addresses, the bytes generated and so forth. The instructions output by gcc -S do not tell me anythi...

Splint barfs on __thread, which is part of C99

Running splint matt@stanley:~/cpfs$ splint -paramuse +gnuextensions cpfs.c Halts on this line: __thread int cpfs_errno; With a parse error: cpfs.c:127:13: Parse Error: Non-function declaration: __thread : int. (For help on parse errors, see splint -help parseerrors.) *** Cannot continue. Checking the documentatio...

C and memory alignment for a binary protocol

I will use this code as an example: typedef struct __attribute__((aligned(XXX),packed)) { uint16_t type; uint32_t id_index; } a_msg; void write_func(){ a_mesg mymsg mymsg.type = htons(1); mymsg.id_index = htonl(5); write(sock_fd, &mymsg, sizeof(a_mesg)); } void read_func(){ a_mesg mymsg read(sock_fd, &mymsg, si...

Linux clock_gettime(CLOCK_MONOTONIC) strange non-monotonic behavior

Folks, in my application I'm using clock_gettime(CLOCK_MONOTONIC) in order to measure the delta time between frames(a typical approach in gamedev) and from time to time I'm facing a strange behavior of clock_gettime(..) - returned values occasionally are not monotonic(i.e prev. time is bigger than current time). Currently, if such a pa...

Compiling using gcc 3.2.3 on RHE 5.3

Some work I'm doing for a client requires me to build using a very old version of gcc on Red Hat Enterprise. We recently shifted from 4.x to 5.3 and I'm hitting some compile errors when I try to build simple example: #include <iostream> int main() { std::cout << "Hello World" << std::endl; return 0; } I get the following: b...