How do I know if the compiler broke my code and what do I do if it was the compiler?

Once in a while C++ code will not work when compiled with some level of optimization. It may be compiler doing optimization that breaks the code or it may be code containing undefined behavior which allows the compiler to do whatever it feels.

Suppose I have some piece of code that breaks when compiled with higher optimizations level only. How do i know if it’s the code or the compiler and what do I do if it’s the compiler?

Error detection in compiler

The error in the expression ” if x>y x=2; ” is detected by

a. Syntax analyzer b. Lexical analyzer c. semantic analyzer

I know that the parenthesis of x>y is missing, but it is not syntax error right? as all the syntaxes are correct, but we are missing a pair of parenthesis.. so is this a semantic error?

Note–> Ans given is syntax error, cant understand why.. 🙁

Compiling a c++ compiler in ubuntu 18.4

I managed to get Eclipse installed but I can not run a program, it says I am missing a binary when I press Run. I have downloaded the files, tcl.tar.gz, mpfr-4.0.2.tar.gz, mpc-1.1.0.tar.gz, isl-0.18.tar.bz2, gmp-6.1.2.tar.lz following the instructions, but I seem to have gotten lost.

I am able to run the “Hello World” in the server, but Eclipse will not connect to it. From what I have read, I have to build a compiler for Eclipse, and I have watched a few videos on it, but Im not sure what the best way to do this would be, nor if the way I choose will work with ubuntu 18.4…

I know I will have to delete Eclipse and reinstall it, so it can find the compiler. I just need to know how to make the make file and what gzs go in what folder! 🙁

Heavily limited premature compiler translates text into excecutable python code

My goal is to write a smaller compiler-like program, which allows me to draw geometric shapes into a 3D Diagram. There is no need for turing-completeness and the program should only be viewed as an exercise and not as a program used by anybody. However, I want the program to have a compiler-like nature.

At the moment the user provides a text file like this:

(1,45,6) (7,8,5) (10,77,88) (99999,1,1) (5,7,6) (1,2,3) (4,5,6) 

These points will be translated into a python file, which will later display all points in a 3D-Diagram when executed. For the moment, I just want it to print out a list of points when executed.

–> [(1, 45, 6), (7, 8, 5), (10, 77, 88), (99999, 1, 1), (5, 7, 6), (1, 2, 3), (4, 5, 6)]

Therefore, I build the following code using C (just to improve C-skills, I am aware that writing it in python would be more applicable)

#include <stdio.h> #include <string.h> #include <stdlib.h>  size_t seek(char* buffer, size_t start, const size_t end, char to_be_seeked); int translateString2Number(char* c, long length); int power(int base, int exponent);  int main(int argc, const char * argv[]) {     if(argc <= 2)return -1;      char file_name[100];     strncpy(file_name, argv[1], 100);     FILE* fp = fopen(file_name, "read");     if(!fp)return -1;      fseek(fp, 0, SEEK_END);     const size_t elements_num = ftell(fp);     rewind(fp);      remove("translation.py");     FILE * python_file_pointer = fopen("translation.py", "ab+");     fprintf(python_file_pointer, "list = []\n");      //Do parsing     char* buffer = malloc(sizeof(char) * elements_num);     fread(buffer, elements_num, 1, fp);      size_t start = 0;     while(start < elements_num){         if(buffer[start] != '(') return -1;         size_t end = seek(buffer, start, elements_num, ')');         if(end == -1) return -1;          size_t comma_pos[2];         comma_pos[0] = seek(buffer, start, end, ',');         comma_pos[1] = seek(buffer, comma_pos[0]+1, end, ',');         if(comma_pos[0] == -1 || comma_pos[1] == -1 )return -1;          char first_number_size = comma_pos[0]-start-1;         char first_number[first_number_size];         for(size_t i = 0; i < first_number_size; i++){             first_number[i] = buffer[start+1+i];         }          char second_number_size = comma_pos[1]-comma_pos[0]-1;         char second_number[second_number_size];         for(size_t i = 0; i < second_number_size; i++){             second_number[i] = buffer[comma_pos[0]+1+i];         }          char third_number_size = end - comma_pos[1]-1;         char third_number[third_number_size];         for(size_t i = 0; i < third_number_size; i++){             third_number[i] = buffer[comma_pos[1]+1+i];         }          if( (first_number_size < 0) || second_number_size < 0|| third_number_size < 0){             return -1;         }         if( (first_number_size > 11) || second_number_size > 11|| third_number_size > 11){ //Avoid potential overflow              return -1;         }          int first = translateString2Number(first_number, first_number_size);         int second = translateString2Number(second_number, second_number_size);         int third = translateString2Number(third_number, third_number_size);          fprintf(python_file_pointer, "list.append((%d,%d,%d))\n", first,second,third);         const size_t value = seek(buffer, end, elements_num, '\n');         if(value == -1)break;         start = value+1;     }      fprintf(python_file_pointer, "print(list)\n");     fclose(python_file_pointer);     system("python3 translation.py");     fclose(fp);  }  int power(int base, int exponent){     int result = 1;     for(int i = 0; i < exponent; i++){         result *= base;     }     return result; }  int translateString2Number(char* c, long length){     int res = 0;     for(int i = 0; i < length; i++){         res += (c[i]-'0')*power(10, (int)(length-i-1));         //printf("\n%d", res);     }     return res; } size_t seek(char* buffer, size_t start, const size_t end, char to_be_seeked){      do{         if(buffer[start] == to_be_seeked)return start;     } while(++start < end);      return -1; } 

compiler defined move constructor with destructor

As per the link [Move-ctor][1], compiler does not generate a default move constructor if we have a user defined destructor.

Code snippet:

 class General { public:     ~General();     General();     void testInitList(); };  int main(int argc, char **argv) {     General b(std::move(General()));     General g = std::move(b);     g.testInitList();     return 0; } 

The code compiles implying that the compiler generated a default move constructor. The code was compiled using gcc version 5.4.0.

Could someone explain why the compiler generated a move constructor and move assignment operator in this case despite have a destructor?

Best, Rahul

error: Cannot run compiler ‘icpc’. Output:

reference to my previous question about cross compilation, i could not to do this work with my raspberry Zero (via USB OTG Connection to my PC LINUX OS), so i decide to compile the program in my Linux PC, i installed again the QT by this way:

cd /home/so/Desktop/trash/3 wget http://download.qt.io/official_releases/qt/5.12/5.12.3/single/ qt-everywhere-src-5.12.3.tar.xz     tar xvf  qt-everywhere-src-5.12.3.tar.xz     cd  qt-everywhere-src-5.12.3 ./configure --prefix=/home/so/Program_Files/Qt_v5_Desktop_Kit     make     make install 

SO when i changed the desktop kit setting in my Qt Creator settings you can see here:

my Qt Creator settings

but now with project like this:

#------------------------------------------------- # # Project created by QtCreator 2019-06-09T18:56:52 # #-------------------------------------------------  QT       += core gui  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets  TARGET = new_sd TEMPLATE = app  # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS  # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0  CONFIG += c++11  SOURCES += \         main.cpp \         mainwindow.cpp  HEADERS += \         mainwindow.h  FORMS += \         mainwindow.ui  # Default rules for deployment. qnx: target.path = /tmp/$  $  {TARGET}/bin #else: unix:!android: target.path = /home/pi/Desktop/$  $  {TARGET}/bin else: unix:!android: target.path = /home/so/Desktop/$  $  {TARGET}/bin !isEmpty(target.path): INSTALLS += target 

when i debug it in my linux pc desktop kit i get this error:

:-1: error: Cannot run compiler 'icpc'. Output: 

I get the icpc is one from this site:

Linux / MacOS: icc ( C ) icpc (C++) ifort (Fortran) 

I have searched the icpc file via my /home/so folder but i don’t find any things.SO have can i solve this problem?

Thanks.

Does compiling a program in visual studio (windows form vb.net) leaves a mac address of the compiler?

I am not making an installer. It is just a form as a portable exe file. Asking because it’s generating links of a external Web API (not mine) that is a openload crawler. Although technically legal (streaming is also legal in my country) I still do not want to be linked to it in any way if it spreads around further from my friends circle. Its very useful if you’re lazy as me and hate ads/malware.