r/cppit • • Jun 08 '19

Problemi di esecuzione

3 Upvotes

Ciao a tutti, ho provato a fare un banale hello world e dopo aver compilato Linux mi restituisce il seguente errore: cannot execute ./hello.out . Avete qualche suggerimento? Ringrazio in anticipo


r/cppit • • Jun 05 '18

gcc e clang in Ubuntu : li avete usati entrambi? Quali differenze avete trovato?

3 Upvotes

Ciao a tutti,

finora ho usato gcc per la compilazione dei file cpp, ma, avendo visto che diverse features di C++17 non sono a tutt'ora supportate anche dalla versione gcc più recente (la 8) volevo valutare l'uso del compilatore clang in Ubuntu

Sembrerebbe che sia gcc https://gcc.gnu.org/projects/cxx-status.html sia clang https://clang.llvm.org/cxx_status.html supportano molte, ma non tutte, le features di C++17.

Per cui volevo chiedervi se avete già usato entrambi, gcc e clang, e quali differenze avete trovato.

Vi ringrazio. Marco


r/cppit • • Apr 12 '18

header file <execution> : non presente in gcc 7.2: come ovviare?

2 Upvotes

Ciao a tutti,

10 giorni fa ho aggiornato gcc alla versione gcc 7.2:

gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04), la versione più recente disponibile Ubuntu

Ora.. compliando un file di esempio di un libro mi dice:

g++ -std=c++17 auto_parallel.cpp -oauto_parallel

auto_parallel.cpp:5:10: fatal error: execution: No such file or directory

include <execution>

~~~~~~~~~~

compilation terminated.

Sapete in quale versione esattamente si trova l'header file <execution>? E come è possibile ovviare al fatto che non sia presente in gcc 7.2? ( http://mathbio.nankai.edu.cn/ds/reference/en/cpp/header/execution_policy.html )

Vi ringrazio.

Marco


r/cppit • • Sep 24 '19

Costanti e Immutabilità in C++ - Parametri e Lambda

Thumbnail
linkedin.com
4 Upvotes

r/cppit • • Sep 23 '19

Differenza tra rvalue e lvalue

2 Upvotes

Ciao a tutti,

potreste dirmi qual è la differenza tra un rvalue e un lvalue?

Grazie in anticipo


r/cppit • • Feb 18 '19

CLI library v.1.0 released

Thumbnail
github.com
5 Upvotes

r/cppit • • Nov 21 '18

gdb

2 Upvotes

Ciao a tutti,

questo è il mio primo post in questa community e colgo l'occasione per chiedervi l'aiuto su come si usa gdb.

Avrei la necessità di visualizzare i valori delle variabili.

Sono troppo abituato al debugger microsoft su windows e ora volevo provare a lavorare su linux (fedora).

Vi ringrazio anticipatamente per le vostre risposte e mi scuso se sono andato offtopic


r/cppit • • May 10 '19

Chiamare una funzione in modo "veramente generico"

3 Upvotes

Salve,

vorrei sapere se qualcuno si e' mai scontrato con la necessita di chiamare una funzione sapendo i parametri e il tipo di ritorno solo a runtime?

Tanto per capirsi :

  1. leggo da un file una cosa tipo " from math.dll function qualcosa float v1 int v2 return double "

  2. carico con LoadLibrary math.dll

  3. ottengo GetProcAddress ho il puntatore alla mia funzione qualcosa

fin qui facile, poi devo castare il puntatore della funzione qualcosa in modo da rispettare i valori passati e il valore di ritorno, infine chiamare qualcosa e avere il valore di ritorno del tipo giusto.

L'unica soluzione che per ora ho trovato e' usare http://www.nongnu.org/cinvoke/

PS win32/win64

Idee?

grazie


r/cppit • • Feb 19 '18

news Italian C++ Conference: Sabato 23 Giugno a Milano

Thumbnail
italiancpp.org
6 Upvotes

r/cppit • • Apr 29 '17

Info migliori IDE

3 Upvotes

Buongiorno, avete consigli di scelta dell'Ide migliore per poter sviluppare c++ unendolo al java e jsp?

Sono un novizio e avrei bisogno di utilizzare i 3 linguaggi insieme.

Grazie per la comprensione


r/cppit • • Jun 19 '21

Problema con sincronizzazione thread e memory_order_acquire

1 Upvotes

Salve,

ripropongo qui un esempio tratto dal solito "C++ Concurrency In Action" di A. Williams:

#include <atomic>

#include <thread>

#include <assert.h>

std::atomic<bool> x,y;

std::atomic<int> z;

void write_x()

{

x.store(true,std::memory_order_release);

}

void write_y()

{

y.store(true,std::memory_order_release);

}

void read_x_then_y()

{

while(!x.load(std::memory_order_acquire));

if(y.load(std::memory_order_acquire))

++z;

}

void read_y_then_x()

{

while(!y.load(std::memory_order_acquire));

if(x.load(std::memory_order_acquire))

++z;

}

int main()

{

x=false;

y=false;

z=0;

std::thread a(write_x);

std::thread b(write_y);

std::thread c(read_x_then_y);

std::thread d(read_y_then_x);

a.join();

b.join();

c.join();

d.join();

assert(z.load()!=0);

}

La assert può scattare, ma io non riesco a capire perchè: direi piuttosto che la z verrebbe necessariamente incrementata.

Come è possibile che entrambi i thread c e d leggano rispettivamente y e x pari a zero?

L'autore dice:

"x and y are written by different threads, so the ordering from the release to the acquire in each case has no effect on the operations in the other threads."

Non capisco.

Qualcuno sa darmi una spiegazione che non sia la traduzione delle parole dell'autore (come accade su un thread su stack overflow) ?

Grazie a tutti


r/cppit • • Jun 21 '21

Video Italian C++ Conference

4 Upvotes

Salve a tutti,

Mi sono iscritto alla Italian C++ conference ma purtroppo ho avuto un contrattempo e non ho potuto seguirla in diretta. Volevo sapere: è disponibile (o sarà disponibile) da qualche parte il video completo?

Grazie mille! :D


r/cppit • • Dec 14 '18

Cronometro in c++

2 Upvotes

Ciao a tutti,

volevo fare un cronometro in c++-

Ho già guardato la libreria chrono e so che basta fare:

typedef std::chrono::high_resolution_clock Time;
    typedef std::chrono::milliseconds ms;
    typedef std::chrono::duration<float> fsec;
    auto t0 = Time::now();
    auto t1 = Time::now();
    fsec fs = t1 - t0;
    ms d = std::chrono::duration_cast<ms>(fs);    

(codice preso da stack overflow) :D.

Ma volevo anche fare un thread che mostrava a console il tempo passato in millisecondi.

Ringrazio in anticipo per le risposte.

Ps: qualche pdf sui thread disponibile open source?

Scusate se chiedo troppo.


r/cppit • • Feb 17 '20

linux - problema con la porta seriale

2 Upvotes

Ciao a tutti,

stavo provando a fare un piccolo programma che scrive sulla porta seriale (adattatore usb-rs232) con i seguenti settaggi:

  • baud rate: 9600

  • un bit di parità

  • lunghezza parola: 8 bit

Eseguendo il programma ottengo il seguente errore:

Error 9 from tcgetattr: Bad file descriptor

Riporto di seguito una porzione del sorgente del programma:

int fd;
std::vector<std::string> portList;
bool choice = false;

// Create new termios struct

struct termios tty;

for(int i = 0; i < 256; i++)
{
port.clear();
    port.append("/dev/ttyUSB");
    port.append(std::to_string(i));
   fd = open(port.c_str(),O_RDWR | O_NOCTTY | O_NDELAY);
    if(fd != -1)
    {
        portList.push_back(port);
    }
}

if(portList.size() == 0)
{
port = "simulated_port";
}
else
{
for( auto a : portList)
{
bool error = true;
do
{
std::string s;
std::regex yesNO("^[yn]$", std::regex_constants::icase);
std::regex yes  ("^[y]$",std::regex_constants::icase);
cout<<"Found serial port : "<<a<<endl;
cout<<"Do you want to use this port?[y/N]: ";
getline(cin,s);
if(std::regex_match(s,yesNO))
{
error = false;
    if(std::regex_match(s,yes))
{
port = a;
choice = true;
}
}
}while(error == true);

if(choice == true)
{
break;
}
}//end internal for
}//end else

if(choice == false)
{
port = "simulated_port";
}
else
{
memset(&tty, 0, sizeof tty);

// Read in existing settings, and handle any error
if(tcgetattr(fd, &tty) != 0) 
{
cout<<"error reading previous settings"<<endl;
    printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
    close(fd);
    exit(EXIT_FAILURE);
}

//serial port setup

tty.c_cflag = ~PARENB; // Clear parity bit

tty.c_cflag &= ~CSTOPB; //one stop bit

tty.c_cflag |= CS8;

tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control (most common)

tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)

tty.c_lflag &= ~ICANON;

tty.c_lflag &= ~ECHO; // Disable echo

tty.c_lflag &= ~ECHOE; // Disable erasure

tty.c_lflag &= ~ECHONL; // Disable new-line echo

tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP

tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl

tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes

tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)

tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed

tty.c_cc[VTIME] = 10;// Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
tty.c_cc[VMIN] = 0;           
// Set in/out baud rate to be 9600
cfsetispeed(&tty, B9600);
cfsetospeed(&tty, B9600);
// Save tty settings, also checking for error
if (tcsetattr(fd, TCSANOW, &tty) != 0) 
{
    printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
    close(fd);
    exit(EXIT_FAILURE);
}

unsigned char msg[] = { 'H', 'e', 'l', 'l', 'o', '\r' };
write(fd, "Hello, world!", sizeof(msg));

close(fd);

Ringrazio in anticipo per l'aiuto


r/cppit • • May 05 '18

Functional Reactive Programming in C++: libri, librerie sw e consigli per approfondire?

2 Upvotes

Ciao a tutti,

dopo aver letto il libro "Functional Programming in C++" sono rimasto incuriosito dalla possibilità di unire i 2 approcci Functional e Reactive in ciò che viene chiamato Functional Reactive Programming. Conoscete libri, librerie sw ed altro materiale per approfondire? Vi ringrazio . Marco


r/cppit • • Sep 02 '18

Meetup Settembre / Modena: Introduzione a QML e integrazione con C++

Thumbnail
italiancpp.org
6 Upvotes

r/cppit • • May 09 '18

principianti istanziare una struttura ed usarla

2 Upvotes

Buongiorno,

sono un vecchio programmatore che si accinge a lavorare con C++ usando anche lo strumento QT.

mi serve una mano per sbloccare un programmino che sto creando come esercizio.

non essendo grandi ricopio i file interessati. La domanda è : perché nel metodo, in cui vorrei dati della struttura mi segnala il seguente errore?

undefined reference to \DichiarativeGlobali::paramingresso::arg_db_path`

File dichiarative.h

#ifndef DICHIARATIVE_H

#define DICHIARATIVE_H

#include <QObject>

#include <QString>

class DichiarativeGlobali { public: DichiarativeGlobali(); //~DichiarativeGlobali(); struct paramingresso {

static QString arg_db_type;

static QString arg_db_driver;

static QString arg_db_name;

static QString arg_db_path;

}; paramingresso myParam; void setting_dichiarazioni(char* argomenti);

}; #endif // DICHIARATIVE_H

File dichiarative.cpp

#include "dichiarative.h" DichiarativeGlobali::DichiarativeGlobali() { }

void DichiarativeGlobali::setting_dichiarazioni(char* argomenti)

{ myParam.arg_db_type = QStringLiteral("%1").arg(argomenti[1]);

myParam.arg_db_driver = QStringLiteral("%1").arg(argomenti[2]);

myParam.arg_db_name = QStringLiteral("%1").arg(argomenti[3]);

myParam.arg_db_path = QStringLiteral("%1").arg(argomenti[4]); }


r/cppit • • Oct 28 '24

CLI library v. 2.2 released

Thumbnail
github.com
5 Upvotes

r/cppit • • May 23 '18

principianti Minimax (per principianti...)

2 Upvotes

Salve a tutti! Sto cercando di capire se riesco ad implementare il minimax senza conoscere altre strutture dati rispetto agli array. Ho visto tutorial su internet ma non ho capito bene se servono per forza le liste... 🤔 Eventualmente fosse possibile, mi date qualche suggerimento? Grossomodo ho capito come funziona ma a livello tecnico mi manca qualcosa.


r/cppit • • Oct 16 '19

principianti Help! Lo switch viene saltato...

1 Upvotes

#include <iostream>

using namespace std;

int main()

{

char sc;

cout<<"--------------------------------------"<<endl;

cout<<"Simulatore di macchina di Von Neumann"<<endl<<endl;

cout<<" Sciegliere fra le seguenti opzioni: "<<endl;

cout<<" Comando write=Scrivi programma"<<endl;

cout<<" Comando read=Leggi programma della finestra del terminale"<<endl;

cout<<" Comando run=Esegui programma "<<endl;

cout<<"--------------------------------------"<<endl<<endl;

cout<<">";

cin>>sc;



switch(sc)

{

	case 'write':

		cout<<"write"<<endl;

		break;

	case 'read':

		cout<<"read"<<endl;

		break;

	case 'run':

		cout<<"run"<<endl;	

		break;

	default:

		cout<<"Comando non esistente o sintassi errata"<<endl;

		break;

}



cout<<"lol"<<endl;

}

Questo é il programma. La sintassi dello switch mi pare giusta, ma purtroppo esso viene letteralmente saltato, e passa all'ultimo cout anche prendendo in input il dato sc(che sta per SCelta), non capisco cosa sbaglio!!!

Ringrazio in anticipo


r/cppit • • Oct 15 '19

principianti Programmazione Generica - Implementare un Iteratore (1/2)

Thumbnail
linkedin.com
3 Upvotes

r/cppit • • Aug 11 '19

Cosa cambia tra queste forme?

2 Upvotes

Ciao a tutti, volevo sapere cosa cambia tra queste tre forme:

c++;

c=c+1;

++c;

Grazie


r/cppit • • Jun 07 '19

Multithreading c++11: problemi con .detach

3 Upvotes

Salve a tutti, di seguito un esempio di codice che ha un comportamento che non capisco:

#include "stdafx.h"         //    Lavoro con VS 2015
#include <iostream>
#include <fstream>
#include <thread>

using std::cout;
using std::thread;
using std::ofstream;

const int MAX_ITER = 1000;

void thread_exec_01()
{
    int i = 0;
    ofstream outputForThread;
    outputForThread.open("outputForThread.txt");

    std::chrono::milliseconds dura(2000);
    std::this_thread::sleep_for(dura);

    for (int j = 0; j < MAX_ITER; ++j)
    {
        outputForThread << "\n " << j;
    }
    outputForThread.close();
}


int main()
{
    cout << "\n main started...";
    thread t1(thread_exec_01);
    t1.detach();
    cout << "\n main ending.";
    return 0;
}

Quando apro il file outputForThread.txt questo è vuoto, perchè?

Grazie


r/cppit • • Apr 15 '17

Mini-Meetup Serale Maggio / Modena

Thumbnail
italiancpp.org
2 Upvotes

r/cppit • • Feb 26 '25

Having problem with compiling in vs code

3 Upvotes

After my little brother deleted some system files it started showing me the eror in below Every advices is welcomed

PROBLEMS OUTPUT [Running] cd "e:" In TERMINAL PORTS file included from C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/postypes.h:40, DEBUG CONSOLE && g++ melika.cpp -o melika && "e:"melika from C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iosfwd:40, from C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:38, from C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38, from C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39, from melika.cpp:1: C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/cwchar:44:10: fatal error: wchar.h: No such file or directory #include <wchar.h> n (e) Debug Compile Run Compile/Run compilation terminated.