Something Wrong with GCC compiler

I am using Arch Linux and when I am compiling and running the following C code,

#include <stdio.h> #include<string.h>  int main(void) {     char s1[]="Hello";     char s2[]="World";      strcat(s1,s2);     int s2_len=strlen(s2);      printf("s1 = %s, s2 = %s and length of s2 = %d.\n", s1, s2, s2_len);      return 0; } 

I am getting the output:

s1 = HelloWorld, s2 = orld and length of s2 = 4. 

Although the output shoud be s1 = HelloWorld, s2 = World and length of s2 = 5. and it is the output when I am using some online IDE.

Can somebody explain me why is this happening?

Error with C compiler while installing Apache

Forgive me I’m totally pretty new to anything server related. I am trying to install APACHE webserver on my Macbook Pro using xcode and everything seems to go fine with the install until the C compiler check:

checking whether the C compiler works… no configure: error: in `/Users/darrinwebster/desktop/httpd-2.4.37′: configure: error: C compiler cannot create executables

I made sure that gcc was installed correctly and also downloaded xcodes command line tools but I’m still getting this error when I try to install Apache.

whereis gcc gives:

/usr/bin/gcc

gcc –v gives:

Configured with:–prefix=/Volumes/Blackbox/Applications/Xcode.app/Contents/Developer/usr –with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin15.6.0 Thread model: posix

Here is the config log:

This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was generated by GNU Autoconf 2.69. Invocation command line was

$ ./configure –prefix=/Darin-Macbook-Pro/local/apache2

———

Platform.

———

hostname = Darrins-MacBook-Pro.local uname -m = x86_64 uname -r = 15.6.0 uname -s = Darwin uname -v = Darwin Kernel Version 15.6.0: Thu Jun 21 20:07:40 PDT 2018; root:xnu-3248.73.11~1/RELEASE_X86_64

/usr/bin/uname -p = i386 /bin/uname -X = unknown

/bin/arch = unknown /usr/bin/arch -k = unknown /usr/convex/getsysinfo = unknown /usr/bin/hostinfo = Mach kernel version: Darwin Kernel Version 15.6.0: Thu Jun 21 20:07:40 PDT 2018; root:xnu-3248.73.11~1/RELEASE_X86_64 Kernel configured for up to 4 processors. 2 processors are physically available. 4 processors are logically available. Processor type: i486 (Intel 80486) Processors active: 0 1 2 3 Primary memory available: 10.00 gigabytes Default processor set: 268 tasks, 1470 threads, 4 processors Load average: 2.28, Mach factor: 1.71 /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown

PATH: /Users/darrinwebster/anaconda3/bin PATH: /usr/local/bin PATH: /usr/bin PATH: /bin PATH: /usr/sbin PATH: /sbin

———–

Core tests.

———–

configure:3131: checking for chosen layout configure:3133: result: Apache configure:3936: checking for working mkdir -p configure:3952: result: yes configure:3961: checking for grep that handles long lines and -e configure:4019: result: /usr/bin/grep configure:4024: checking for egrep configure:4086: result: /usr/bin/grep -E configure:4102: checking build system type configure:4116: result: x86_64-apple-darwin15.6.0 configure:4136: checking host system type configure:4149: result: x86_64-apple-darwin15.6.0 configure:4169: checking target system type configure:4182: result: x86_64-apple-darwin15.6.0 configure:4212: configure:4214: Configuring Apache Portable Runtime library… configure:4216: configure:4257: checking for APR configure:4402: result: yes

Results of testing different compiler optimizations of GNU GCC are confusing

I tested out a few different compiler optimizations on GNU GCC, in the CodeBlocks IDE. With each different optimization I ran the same test: I let my program try to build as big of a tree as it could in 1 second. The nodes of the tree were objects of a class I created.

Results:

[-O1]: 78,235 nodes generated. [-O2]: 78,235 nodes generated. [-O3]: 78,235 nodes generated. Optimize more (for speed) [-O1]: 773,019 nodes generated. Optimize even more (for speed) [-O2]: 773,019 nodes generated. Optimize fully (for speed) [-O3]: 222,072 nodes generated.

So this is confusing. Standard O1, O2, O3 all perform exactly the same. I made sure to recompile each time I adjusted the compiler settings, so I don’t think there’s any error on my part.

The extra optimizations for O1 and O2 also perform exactly the same, but they perform significantly better than the O3 extra optimization (the optimization I assumed was for max speed).

Could anyone explain this?

EDIt – The exact same number of nodes generated by certain optimizations is actually to be expected, I just remembered this. The program performs iterative-deepening growth of the tree, so the number of nodes grows in huge chunks at a time.

g++ compiler and error undefined reference

i use linux and g++ compiler for cplusplus and i made a class called Command.h with Command.cpp. my code is below

main.cpp

#include <iostream> #include <string> #include <ctime>  #include "./people.h" #include "./Command.h"  using namespace std; int main() {       string CMD="";     cout << "Type Your Valid Command To Do Action"<<endl << "   help To show help-Menu\n\n";      bool ConTact(false);      BeGiN:     do{          cin >> CMD;         Cmd CODE(CMD);     }while((cin>>CMD));       while(!(cin>>CMD)){         cout << "Unvalid Input :)\n\n";          goto BeGiN;     }  } 

and my Command.h

#pragma once #include <iostream> #include <string>   using namespace std;  class Cmd{     public:         Cmd(string);         void Help();      private:         string _name; }; 

and my Command.cpp:

#include <iostream> #include <string> #include "./Command.h"    Cmd::Cmd(string code ){ cout <<" hi \n";  if(code =="help");//show help menu ; else if(code=="add");//show add contact menu else if(code=="rm"); // show remove contact menu else if(code=="change"); //show change menu else if(code=="ls"); //show list of types of contacts else if(code=="ls-l"); //show list of favorit contact else if(code=="ls-f"); //show list of family contact else if(code=="ls-d"); //show list of friends contact else if(code=="ls-fe"); //show list of female contact else if(code=="ls-ma"); //show list of male contact else if(code=="ls-best"); //show list of 10 best favorite contact else if(code=="ls-last"); //show list of 10 lastest added contact else if(code=="ls-d"); //show list of friends contact 

}

when i typed g++ main.cpp in terminal a strange error occurred

/usr/bin/ld: /tmp/ccWpq3Ix.o: in function `main': main.cpp:(.text+0xc6): undefined reference to  `Cmd::Cmd(std::__cxx11::basic_string<char, std::char_traits<char>,  std::allocator<char> >)'  collect2: error: ld returned 1 exit status 

what should i do?? i used visual studio code.

Compiler Design

The SLR(1) parses AFAIK does not have any lookahead with it then why do we write it as SLR(1) and not as SLR(0). The thing about parsers which I read online taught me that if it’s LR(K) then K represent the number of lookahead symbols. Thereby it’s not making much sense to me.

Kindly help me here

Thanks in advance!

Writing a Compiler – .reloc section of the COFF

I’m looking for a little bit of direction in writing a compiler. I’ve written in Common Intermediate Language, C#, and various other .NET languages; I’ve written my own Metadata Parser and now I’m trying to understand the various aspects of the Portable Executable (PE) layout. One thing that somewhat befuddles me is the .reloc section.

I have the Relocs parsing (or at least I think I do? 🙂 and I wanted to know, within .NET libraries they usually have a single Reloc block with a single HighLow (IMAGE_REL_BASED_HIGHLOW, or just 3) reloc at a given offset that changes. When I go to writing my own PE Header and COFF sections, how do I calculate the Relative Virtual Address of the block, and the Offset (lower 12 bits) on the TypeOffset entry that follows that block header?

I’m currently using the pecoff_v83.docx (Microsoft Portable Executable and Common Object File Format Specification Revision 8.3) from Microsoft’s website, but I think there’s a step I’m missing out on.

I’ll link a relevant post: How are PE Base Relocations build up?

^ That helped me parse the Reloc entries, but parsing them and generating the data that goes into them are different questions.

Does the output of a compiler depend on the OS you are using?

In the company I am working in we have a management software, written by an external programmer. Let’s call the software PK. PK was initially written in the 90s using C++. Since then it was regularely updated and maintained but in its core it always remained a software based on 90s technology.

We are currently in the process of migrating from Windows 7 to Windows 10 and I recieved one of the first Win 10 PCs in order to test if everything works as expected on the new OS. Everything worked but PK. PK suddenly had frequent crashes. I told the software developer that there are issues with PK under Win 10 but even after numerous updates and changes to the code we still had these crashes. The developer just couldn’t figure out why it crashed although it seems to be related to the memory management of PK.

The last straw the developer saw, was to compile the software on my Win 10-PC. I compiled the source code with exactly the same version of Visual Studio 2008 and suddenly it worked. No more crashes.

So my question is:

Can it be that the same Code, compiled by the same compiler produces a different binary dependent on the version of Windows (Windows 7 and 10)?

And if so: Why?