Click here to Skip to main content
15,885,546 members
Everything / GCC

GCC

GCC

Great Reads

by Mikhail Semenov
This article shows that double-ended vector is much faster than std::deque and should be preferred.
by altomaltes
This code calculates square root of an integer on a few assembler code lines.
by Oscar-Tark
In this article, we will be looking at a more advanced version of a buffer overflow attack.
by Mikhail Semenov
This article proposes a mapping algorithm, called Segmented Map, which is almost as fast as Flat Map is random access and enumeration of elements and close to std::map in insertion of elements.

Latest Articles

by ToughDev
Retro68 GCC-based SDK for 68K Mac
by ToughDev
How to build Wireshark 1.12.5 static binaries for CentOS 5
by Steffen Ploetz
Is LINQ the right technology for processing large amounts of data in runtime-relevant environments?
by Mikhail Semenov
This article proposes a mapping algorithm, called Segmented Map, which is almost as fast as Flat Map is random access and enumeration of elements and close to std::map in insertion of elements.

All Articles

Sort by Score

GCC 

10 Sep 2022 by Mikhail Semenov
This article shows that double-ended vector is much faster than std::deque and should be preferred.
5 Jun 2019 by altomaltes
This code calculates square root of an integer on a few assembler code lines.
27 May 2021 by Oscar-Tark
In this article, we will be looking at a more advanced version of a buffer overflow attack.
6 Apr 2013 by CPallini
Under Linux you usually want to make .so files (Linux can't consume Windows DLLs).Here you may find a guide: "Intro to Linux Shared Libraries (How to Create Shared Libraries)"[^].
8 Aug 2013 by Manfred Rudolf Bihy
You're using the wrong format code %d (Scan an integer as a signed decimal number) it should be %s (Scan a character string).Read here to learn more: http://en.wikipedia.org/wiki/Scanf_format_string[^]Regards,— Manfred
18 Sep 2022 by Mikhail Semenov
This article proposes a mapping algorithm, called Segmented Map, which is almost as fast as Flat Map is random access and enumeration of elements and close to std::map in insertion of elements.
6 Nov 2018 by CPallini
You should declare your variable extern in the header and define it in the source file (without the static keywork: static in source file provides internal linkage). See, for instance: Internal linkage with static keyword in C - Stack Overflow[^].
6 Nov 2018 by Richard MacCutchan
You should not be defining them in the header file if they are static, just in the .cpp file. If you are trying to create global variables then you should declare them extern in the header, and give them a value in one .cpp file only, like: // header.h extern int variable; extern int...
26 Mar 2019 by thoughts-on-coding
Introduction into an Automated C++ Build Setup with Jenkins and CMake
9 Jun 2019 by cassert24
Template code for basic reflection functionalities (e.g., dynamic casting, instance type comparison, class name) with C#-like singular inheritance rule (a.k.a, one-base-multiple-interface rule)
29 Feb 2020 by Oscar-Tark
A basic formatted string exploit shows you how small errors in programming with the printf function can be a lethal weapon for hackers looking to compromise a system.
11 Nov 2011 by panini_sp
I need help understanding Union of Intervals based on Advanced Data Structures Book by Peter Brass. Attached is the section of the book that Im trying to Understand starting from the middle of the page 163 where it says "A fully dynamic structure to maintain the measure of a union of...
24 Dec 2012 by CPallini
You usually don't pass the whole name of the library (that is complete with its extension), for instance when you link with librt you don't pass directly librt.so or librt.a, but use instead the -lrt switch on command line (please note you do the same thing on Windows, for both dynamic or static...
27 Mar 2013 by Zoltán Zörgő
Because you defined a type. Thus implicit type casting won't work. See: http://en.cppreference.com/w/cpp/language/implicit_cast[^]
25 Sep 2013 by OriginalGriff
Try adding the -lm switch to your gcc command to load the math library:gcc MyProgram.c -o MyProgram -lm
16 May 2014 by Bartlomiej Filipek
Description of the implementation of my particle container
14 Jul 2014 by nv3
The address of a piece of code is usually determined by the linker, not the compiler. What you see in an assembler code listing is a procedure relative address. The linker will combine the code from the various compilation units and then construct the executable or dll. And even in the moment...
19 Jun 2015 by Sergey Alexandrovich Kryukov
First, write forward declaration of one of the struct, then fully define the other struct below, and, finally, fully define the first structure represented by the forward declaration above. The C syntax is pretty awkward; please...
18 Sep 2017 by Shmuel Safonov
Creation a numeric library that calculates with quadruple floating-point precision and used from MSVC C/C++ code
5 Nov 2019 by Stefan_Lang
I strongly suspect this is a bug in the compiler's code optimization: M isn't read by the program, so the compiler will try to eliminate code referring to it - maybe it messed up this optimization because the statement cin>>N>>M internally translates into a nested function call:...
3 Dec 2019 by thoughts-on-coding
Matrices are a key concept in solving linear equation systems. Efficient implementations of matrices are not only considering computation complexity but also space complexity of the matrix data.
22 Mar 2021 by Rick York
There are several errors in this code. Here's one : MemMgr::InsertBlock(void* block) { if(sizeof(block) > MAX) throw runtime_error("Blocksize too big"); if(_blocks.size() > MAX) throw runtime_error("Out of room"); ...
24 Apr 2021 by Aghast (nj)
Command (1) compiles the .c file to a .o (object) file, then stops. Command (2) compiles the .c file to an object file, then links the object file with the C standard library to produce an executable file named file. Both commands drop their...
6 Dec 2021 by k5054
Have you tried the always_inline attribute? See the attribute specification documentation over at cppreference.com[^] That requires C++-11, so will hopefully be available for your G++ tool chain. Also see Optimize Options (Using the GNU Compiler...
12 Apr 2012 by Richard MacCutchan
Lines such as this are used by the preprocessor to include or exclude sections of source code in a module. Thus:#define __something__#if defined(__something__)// this source code will be included#else// this source code will NOT be included#endifAs to your second question it...
14 Apr 2012 by Aescleal
(really old question, but there's no solution and it might be useful for other people later)If your server is single threaded (which I doubt) then you can use strtok to slice chunks off the string using the ? and @ characters as delimeters.If you're writing a multithreaded server then on...
28 Aug 2012 by Pablo Aliskevicius
In a terminal, type 'man kill'. It won't kill neither man nor woman ;).Exit man by typing 'q'.Hope this helps, Pablo.
2 Sep 2012 by Richard MacCutchan
See the kill(3)[^] man pages for details of how to kill a process.
3 Sep 2012 by Andreas Gieriet
You ask for a C solution.I would solve it in a bash script using kill[^] and mail[^].For programming in C, use kill[^] and fall back to the mail command line tool to send the notification (via system[^]).See also wikipedia[^] for an overview on kill and wikipedia[^] on unix mail...
8 May 2014 by pitonyak
I use the following in my PRO filesQuote:QMAKE_CXXFLAGS += -std=c++0xDetermine which flags are required by your compiler (and it looks like your error message makes two suggestions).
17 Jul 2014 by Garth J Lancaster
char *s; doesn't allocate any memory for the scanf read - it just declares a pointer - so you need to use (for example) s = malloc(100); to get enough space for a 99 character string (plus the terminating nul) iircthe issue then is, how do you ensure your user doesn't type more than 99...
17 Jul 2014 by Leo Chapiro
You have not allocate any memory for this string, the quick and dirty fix would be:#include int main(){ char s[255],i; printf("Enter a string: "); scanf("%s",s); for(i=0; s[i]!='\0'; ++i); printf("Length of string: %d \n",i); return 0;}
17 Jul 2014 by CPallini
A nice reading: "String overflows with scanf"[^].
15 Dec 2014 by OriginalGriff
Probably, you can't: most code resides in memory segments marked as "executable" or "read only" and attempts to change them generally result in access violation errors.And more to the point, why?Self modifying code is often a sign that you have done something very, very wrong, and often...
22 May 2015 by Sergey Alexandrovich Kryukov
Mouse has nothing to do with focus. Use the function SendInput:https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].The function is low-level; it works as the raw mouse and keyboad events came from the device driver.Don't use the functions mouse_event...
19 Jun 2015 by CPallini
Sergey already gave you the correct answer, I just add an example:File a.h #ifndef __A_H__ #define __A_H__ struct A; // forward declaration of A struct B { struct A * element; }; #endif // __A_H__File b.h #ifndef __B_H__ #define __B_H__ struct B; // forward declaration of...
1 Nov 2016 by Philippe Mori
The first problem with your code is that identifier that begin are reserved for the system. In your case, you use the well known macro _T as a parameter for your template.Unicode Programming Summary[^]The next problem with your code is inconsistent use of int and size_t for the size....
30 Mar 2017 by Mehedi Shams
Hi Member 13095321,There is a mistake in this line:for(i=2; i
22 Feb 2018 by Jochen Arndt
It is difficult to answer that without knowing what you are tyring to build and on witch system with which compiler. As suggested in the output you should have a look at the config.log file. That should contain error messages from the started tools (the C compiler) which might indicate what...
11 May 2018 by OriginalGriff
Use the Process class to execute gcc: Process Class (System.Diagnostics)[^] Be aware: if you "randomly" run applications you are given as source, you are opening your whole machine up to whatever the app writer chooses to do. I would STRONGLY recommend that you look at using a VM if you value...
15 Sep 2018 by Patrice T
Quote: Flight search you work as a software developer for a major airline This smells like 1 of those challenge sites contests. The same question have been asked already today, you should team with your class/contest mates. All the interest of those contests is to know if you can solve it or...
15 Jul 2020 by KarstenK
You better implement a polygon class which takes the string as input. In the constructor or better parse function use must convert the string numbers into numbers with some function as atoi because math with strings is nonsense . This is also...
10 Sep 2020 by CPallini
You code looks like a mix of C and C++ programming languages. Typically, the C programmer writes #include typedef struct { char firstname[20]; char lastname[20]; int age; } student_info; int main () { student_info student[]...
22 Mar 2021 by Greg Utas
It's hard to debug just looking at a sketch, but void* is the size of a pointer. So when you index _mempool, you're going to be incrementing by the size of a pointer (32 or 64 bits), not a byte. I would suggest trying uint8_t* instead of void*....
24 Apr 2021 by Dave Kreskowiak
-c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file. By default, the object file name for a source file is made by replacing...
7 May 2023 by ToughDev
How to build Wireshark 1.12.5 static binaries for CentOS 5
27 Dec 2023 by Richard MacCutchan
See B2 User Manual - 1.84.0[^].
17 Nov 2011 by coffeenet
Hi,I am trying to gprof my program. I want a line-by-line profiling.However, I can't seem to get the syntax write. I am using "make" and not "gcc" so please help only with suggestions that fit make. I wouldbe very grateful if you can give me the full "make" syntax.Based on this...
18 Nov 2011 by Richard MacCutchan
The '-l' option is not valid for gcc so it assumes that it, and all following options, should be passed to the linker. You need to check which options are valid for gprof, as described here[^], and for gcc as described here[^].
12 Jan 2012 by nicetuxedo
The code compiles under gcc 4.4 with the following commandgcc -fms-extensions experiment.cUnder gcc 4.6 I get errors#include typedef unsigned char uint8_t;typedef unsigned short uint16_t;typedef signed char sint8_t;typedef signed...
12 Jan 2012 by Andreas Gieriet
You need to give names to all union members.In your code, the sub-unions have no name -> no declaration warning.With the extension, the anonymous sub-unions seem to introduce their members directly into the current union. This results in having the members raw, etc. declared twice.Your...
14 Jan 2012 by 01.mandar
i have set up target fs on /home/myself/filesys/bin..etc//GCC compile:host $ arm_v5t_le-gcc hello.c -o helloRun:target $ cd /opt/hellotarget $./helloi have installed opencv2.3 on host ubuntu machine now i want opencv to be ported to DM6446 so i follow 1 uncompress opencv2.3...
28 Mar 2012 by Dawood Awan
guys need help... I Am Writing a web server and I receive the data from form using the get method and i receive the dataGET /?itemnumber=1&itemquan=2&firstname=Dawood&lastname=Awam&city=Atd&cardno=123How can i Extract the Variables.. of itemnumber, itemquan,etc...
12 Apr 2012 by Member 8811020
Hello,what does it mean if something is declared like:#define __something__ ?How do i know whether i can use it in another file? I have tried some arguments from different libraries to read in my c code, but haven't figured out, on what it really depends. For instance i have the...
3 Jul 2012 by NewMember2000
I am developing a Java program in Eclipse. I need to compile a input C file in this Java program. So I used the below code.Process process = Runtime.getRuntime().exec(new String[]{ "C:/cygwin/bin/bash", "-c", "/usr/bin/gcc /cygdrive/d/MyFile.c -o /cygdrive/d/MyExe"});I...
3 Jul 2012 by Peter_in_2780
I'm pretty sure it's because you are trying to mix two ways of passing the arguments to exec().Try this:Process process = Runtime.getRuntime().exec(new String[]{"C:/cygwin/bin/bash","-c /usr/bin/gcc","/cygdrive/d/MyFile.c","-o /cygdrive/d/MyExe"});or Process process =...
4 Sep 2012 by Jochen Arndt
I don't know such function. But you may write your own by listing and parsing the information from the /proc/[pid] entries in the proc file system (see man 5 proc[^]).Another solution would be execution of the ps command with the popen() function and parsing the output for the name of the...
19 Oct 2012 by Arun Kumar K S
Hi, I checkout and recompiled the source of Songbird player on windows it compiled and get a new executable.Building Songbird[^] I am stuck with from where I can change the name and icon of executable in Songbird source ?please help me any one knows about this.....
19 Oct 2012 by Richard MacCutchan
You can change the object name by editing the songbird.mk file. Similarly you can add your own icon into the resources and use that in place of the default.
31 Oct 2012 by YvesDaoust
Hi all,I am trying to switch from Eclipse to Visual Studio to compile some of my projects more comfortably. This is not a new problem I guess.My need is as follows: - be able to manage all source files in a project using the Solution Explorer; - be able to specify compilation...
8 Nov 2012 by PrafullaVedante
Hi,I am defining all constants in a .h file. Earlier it were #defines . I am replacing it with const .Header file looks like namespace preprocessing{ namespace generaldef { const int BASE = 0; }}for this code i am getting the following error...
5 Dec 2012 by coffeenet
Hi,I have successfully cross-compiled a program on an x86-64 machine. However, when I try to run on my target machine sh4a, I get the following error:./ioq3ded.sh4a: /lib/libc.so.6: version `GLIBC_2.11' not found (required by ./ioq3ded.sh4a)The details of the two machines are as...
10 Dec 2012 by Arun Kumar K S
I created one application for Ubuntu that reads data from serial port and save to a file. But when I run the application that wont work. One permission denied Issue. That is working when I run from terminal using sudo ./AppName an type the password after that. How I can run and work it...
11 Dec 2012 by E.F. Nijboer
You can simply give the user the rights needed. Try this:usermod -a -G dialout MY_USER_NAMEGood luck!
17 Dec 2012 by SandiegoSSD
Hey guys I'm writing a C code in Atmel Studio 6.0 with GCC C compiler. Essentially I'm doing USART communication on a microcontroller, and I found a sample code(a header file) that handles sending/receiving (Tx/Rx) using a circular receiving buffer from an Atmel employee's...
17 Dec 2012 by nv3
char Command_String[BufferCount] ; while (BufferCount--) strcat(Command_String,RingBuffer_Remove(&Buffer));That won't work in C. You cannot allocate an array of char on the stack (as auto variable) with a variable length. The length must be know at compile time....
18 Dec 2012 by SandiegoSSD
This is a narrow-down from my previous post. I'm trying to use some functions that implement a Ring buffer in USART. They are defined in a header file.http://www.fourwalledcubicle.com/files/LightweightRingBuff.h[^]I've attempted to use these functions in main.c, but I think somewhere I screw...
18 Dec 2012 by OriginalGriff
It's difficult to be sure quite what is wrong without actually runningthat, but... Did you mean to only send data when it wasn't "ABC"? if (strncmp(Command_String,"ABC",3))//another screw up? usart_printstring(Command_String);Which conflicts with your earlier...
18 Dec 2012 by nv3
*Command_String = RingBuffer_Remove(&Buffer); // is this a screw up? Command_String++;Yes, it is. Don't you want to save the pointer to your buffer first? Otherwise, the following strncmp(Command_String,"ABC",3)is not seeing the string that you just copied in, but...
24 Dec 2012 by Pranit Kothari
Hi,I have mostly worked in Windows, and recently I started working in Linux. I have a doubt. I have used Visual Studio as IDE in Windows and used Makefile in Linux.There are two types of libraries in Windows (VC++), static library (.lib) and DLL. It is quite obvious (isn't it?) if I link...
25 Dec 2012 by Sergey Alexandrovich Kryukov
Please see my comment to the question, and then, this: http://gcc.gnu.org/onlinedocs/[^].—SA
27 Mar 2013 by Keanu L
#include typedef enum{red=1,blue,green}color;void set_color(color *c){ *c = blue;}int main(){ //int a = 3; //set_color(&a);//why this error? //set_color((color *)(&a));//It is right color c = red; set_color(&c); // this is right; return 0;}i...
27 Mar 2013 by OriginalGriff
Because it is trying to prevent you making a mistake, and you not realizing it.When you writeset_color((color *)(&a));You are explicitly converting it - telling the compiler "this is the value I wanted to send, I know what I am doing" so it lets it through.When you...
27 Mar 2013 by H.Brydon
In C (and C++), the datatypes 'int' and 'enum' are partly typesafe. For example:typedef enum {E0 = 0, E1 = 1} ENUMtype_t;ENUMtype_t e = E0; // legalint i = 0; // legali = E0; // legale = 0; // legal(!)e = 1; // error(!)e = i; ...
6 Apr 2013 by 125Azazelo
Hi i have beginner question how to make .so and .dll from .cpp in Linux?I have simple project no thread , 2 .h files ,and 2 .cpp files.
24 Jun 2013 by unscathed18
Hi, there are a few things I like to ask related to Codeblocks IDE with GCC/G++:1) I'd like to know if there's any good tutorial or web explaining how to exploit gcc's debug options. What I mean is, my intention is that when I use the 'debug' build instead of 'release' build, I want for...
8 Aug 2013 by sid2x
I am developing a simple program in C,but I encountered a problem :My Code :#includeint main(){ int menuinpt; printf("Welcome to C game!!!!\n"); printf("1. Play Game\n"); read: printf("Enter a Command to start : "); scanf("%d", &menuinpt); if...
25 Sep 2013 by drlucas
I am running into a problem with the pow function in my program. The function is part of a for loop and here is the code section:for( year = 1; year
23 Oct 2013 by Captain Price
Try the ICU library:http://site.icu-project.org/[^]
17 Jul 2014 by Jeevan83
guys, whats wrong here?#include int main(){ char *s,i; printf("Enter a string: "); scanf("%s",s); for(i=0; s[i]!='\0'; ++i); printf("Length of string: %d \n",i); return 0;}output:Enter a string: jeevanLength of string: 6 Segmentation fault...
20 Jul 2014 by Sergey Alexandrovich Kryukov
You can use#include //...int (_cdecl * fpointer)(const char*) = &puts;// where int (_cdecl * fpointer)(const char*) declares the variable "fpointer"// of the type "pointer to the function accepting one argument of the type "const ''char*"// and returning int"// or...
26 Jul 2014 by Manikandan10
You can't do that. C++ won't allow it. Consider any other programming language that don't use these brackets. Try assembly language.
9 Dec 2014 by shang12
I have a project C++ in Qt5 (Ubuntu 64bit). It ran normally on my computer.I have just reinstalled ubuntu 14.10 on my computer. I have also installed all necessary packages (Qt, other libraries) but there are many linking errors when rebuilding my project.qstring.h: error: undefined...
9 Dec 2014 by Jochen Arndt
Q_COMPILER_REF_QUALIFIERS is set in qcompilerdetection.h according to the used compiler and general settings. So it should not be changed.To ignore the setting, define QT_COMPILING_QSTRING_COMPAT_CPP (as indicated by your excerpt from qstring.h). It may be also necessary to define other...
15 Dec 2014 by javadyousefi
I want to modify next instruction before it fetches, in best answer of this question in foo function, *p points to the next instruction in main function. I want to modify content of where *p points at. For example I want to change the next instruction to a jump instruction. How to I can do...
23 Feb 2015 by FranxCDO
** Edited **I tried changing the mentioned Jacobi algorithm to fixed point using libfixmath but I am not getting right results. What did I miss??edited Jacobi codemakefile**************************** Fisrt post ********************************************C newbie here. I...
23 Feb 2015 by Daniel Pfeffer
Translating numerically-sensitive calculations to fixed point is a recipe for trouble and hard-to-find bugs - overflows, underflows, rounding errors, and other problems that would be masked by a floating-point implementation can easily crop up. Try to avoid it if at all possible!I've just...
1 Mar 2015 by FranxCDO
I want to find the eigenvalues and eigenvectors of a 3x3 matrix. My numbers are stored in fixed-point format (16.16 to be exact).Note that I don't mind much about the performance, but simply implementing an algorithm that does the job.The code below, when you build it and run it (with...
22 May 2015 by Sébastien FAVIER
Hi,Excuse me for my bad english level, i'm french studentI develop a c++ application for move and clic automatically on application's buttons with my cursor who can't support command line, but GUI only.With windows.h, I tested...
25 May 2015 by Sébastien FAVIER
Thank you for your reply! :-)I will test this, I keep you informedBest regardsSébastien FAVIER
19 Jun 2015 by Member 11779222
If I have the following C code:struct A{struct B* element;}struct B{struct A* element;}main(){}How do I compile it if when I declare the variable element of type "struct B*" this type wasn't defined yet?And how would I make the makefile and the header files if I had those 2...
21 Aug 2015 by salece
Hi every body,I have a big problem. here a test code of Dll :main.h #pragma once #define BUILD_DLL #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif ...
16 Nov 2015 by Jochen Arndt
So you have an executable and a shared library. The library exports symbols to be used by the executable. But you also want the library to access a symbol from the executable. This is called 'reverse dependency' and your executable must also export the symbol. This can be done by using the...
3 Dec 2015 by Albert Holguin
If you really named your library Dll.dll, that's a horrible name! Aside from that, I'd check what Richard suggested above (make sure there's a path to the library or its in a good default location) and also check with a tool like Dependency Walker[^] to make sure there isn't some other...
8 Mar 2016 by Shivangi_K
I have recently downloaded netbeans 8.1 for my 64bit computer, I plan to use it for c/c++ projects. I also downloaded cygwin64 tool for compilation. I followed every step for the tutorial and changed the env variable path to the bin of cygwin, however, my Netbeans cannot recognize standard...
30 Aug 2016 by Member 12712046
Here is a project source code folder for c/c++, I want to write a small and fast tool/script to get the filename, line number, and function name for all source files . For example, I want it will output like below: ./src/a.c line 1500 call func1(); ./src/a.c line 1600 call func1();...