GCC : From 2.95 to 3.2

Similar documents
Chapter 15 - C++ As A "Better C"

Programmazione. Prof. Marco Bertini

Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide:

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

CE221 Programming in C++ Part 1 Introduction

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

COMP322 - Introduction to C++

C++ Exception Handling 1

Object-oriented Programming in C++

CS2141 Software Development using C/C++ C++ Basics

Introduction to C++ Systems Programming

What will happen if we try to compile, link and run this program? Do you have any comments to the code?

CS3157: Advanced Programming. Outline

UEE1303(1070) S 12 Object-Oriented Programming in C++

Homework 4. Any questions?

Intermediate Programming, Spring 2017*

Exercise 1.1 Hello world

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

CS

Type Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works

Program Organization and Comments

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Casting and polymorphism Enumeration

6.096 Introduction to C++ January (IAP) 2009

CSE 333 Lecture 9 - intro to C++

C++ Namespaces, Exceptions

CS302 - Data Structures using C++

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Lab 1: First Steps in C++ - Eclipse

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

Introduction to Programming

G52CPP C++ Programming Lecture 18

Templates (again) Professor Hugh C. Lauer CS-2303, System Programming Concepts

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

PROGRAMMING IN C++ CVIČENÍ

Function Templates. Consider the following function:

Lecture 10. Command line arguments Character handling library void* String manipulation (copying, searching, etc.)

Informatik I (D-ITET) Übungsstunde 9, Hossein Shafagh

C++ For Science and Engineering Lecture 15

G52CPP C++ Programming Lecture 16

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Computer Science II Lecture 1 Introduction and Background

PHY4321 Summary Notes

Programming. C++ Basics

CPSC 427: Object-Oriented Programming

More Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference

Operator overloading

CS 376b Computer Vision

Why C++ is much more fun than C (C++ FAQ)?

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Assignment #1 Advanced Programming in C /2018. NPRG051 Advanced programming in C++ - Assignment #1

Fast Introduction to Object Oriented Programming and C++

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

CSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors

CS93SI Handout 04 Spring 2006 Apr Review Answers

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

A Tour of the C++ Programming Language

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

CSE 303: Concepts and Tools for Software Development

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

C++ Templates. CSE 333 Autumn 2018

Programming in C++: Assignment Week 8

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Streams. Ali Malik

CS 11 C++ track: lecture 1

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

W3101: Programming Languages C++ Ramana Isukapalli

Intermediate Programming, Spring 2017*

Numbers. John Perry. Spring 2017

ECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++

Exceptions, Case Study-Exception handling in C++.

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

Starting to Program in C++ (Basics & I/O)

Input And Output of C++

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CSE 333 Lecture smart pointers

Program template-smart-pointers-again.cc

Short Notes of CS201

Lecture on pointers, references, and arrays and vectors

Professor Terje Haukaas University of British Columbia, Vancouver C++ Programming

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

QUIZ. What are 3 differences between C and C++ const variables?

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates

A Tour of the C++ Programming Language

CS201 - Introduction to Programming Glossary By

CSE 333 Lecture smart pointers

ECE 461 Fall 2011, Final Exam

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Polymorphism Part 1 1

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O

Transcription:

GCC : From 2.95 to 3.2

Topics Simple changes name of standard include files, std::endl, iostream, throw statements, vector iterators More complicated changes string streams, parameterized macros, hash_map Finer C ++ concepts types of enumeration, typenames 2/19

Hors d oeuvre (simple ones)

Include Files No more.h at the end of standard include files 32 official include files, listed in the C++ standard in section 17.4.1.2 compatible with gcc 2.95 No #ifdef #include <math.h> #include <stdio.h> #include <math> #include <stdio> 4/19

std::endl and co Usage of Namespace std:: is mandatory for objects of the standard library (endl, cout, ) compatible with gcc 2.95 No #ifdef cout << Hello World << endl; cerr << Actually, there s no errors << endl; std::cout << Hello World << std::endl; std::cerr << Actually, there s no errors << std::endl; 5/19

iostreams cerr and cout are defined in <iostream>. You must include this file in order to use them. Also don t forget the std namespace! int void main (int argc, char** argv) { cout << Hello World << endl; } #include <iostream> int void main (int argc, char** argv) { std::cout << Hello World << std::endl; } 6/19

throw statements If a class B inherits A and a virtual method A is redefined in B, the eventual throw specification in A must be there in B too. compatible with gcc 2.95 No #ifdef class A { virtual void foo (int a) throws MyException; } class B { virtual void foo (int a); } class A { virtual void foo (int a) throws MyException; } class B { virtual void foo (int a) throws; } 7/19

Iterators and pointers An iterator on a vector type has nothing to do with a pointer to an element of the vector. In particular no cast between the two is allowed. compatible with gcc 2.95 No #ifdef std::vector<int> myvec; int* firstelement = myvec.begin(); std::vector<int> myvec; std::vector<int>::iterator firstelement = myvec.begin(); 8/19

Main dish (More complex ones)

string streams The standard library changed for string streams. The include file is now sstream (was strstream) and the types i/ostringstream (was i/ostrtream) NOT compatible with gcc 2.95 use #ifdef compatible with windows same case for new compiler and windows uses now std::string as underlying type instead of char* code simplifications 10/19

string stream example const int buffer_size = 256; char buffer[buffer_size] = {0, 0}; std::ostrstream ost(buffer, buffer_size); ost << pv->physvolname << : << pv->tag(); const unsigned int len = strlen(ost.str()); char *resstr = new char[len+1]; strcpy(resstr, ost.str(), len); resstr[len] = 0; std::string result(resstr); delete[] resstr; (1) #if defined ( GNUC ) && ( GNUC <= 2 ) (1) #else std::ostringstream ost; ost << pv->physvolname << : << pv->tag(); return ost.str(); #endif 11/19

parametrized macros The usage of ## is more strict than before. One can no more put them if not needed compatible with gcc 2.95 No #ifdef #define IMPLEMENT_SOLID(x) \ static const SolidFactory<##x##> s_##x##factory ; \ const ISolidFactory&##x##Factory = s_##x##factory ; #define IMPLEMENT_SOLID(x) \ static const SolidFactory<x> s_##x##factory ; \ const ISolidFactory& x##factory = s_##x##factory ; 12/19

hash_map There is no hash_map in the standard library. Thus the include file hash_map of gcc 2.95.2 has become ext/hashmap. The type is no more std::hash_map but gcc_cxx::hash_map Solution : play with using keyword inside an #ifdef #ifdef _WIN32 #include "stl_hash.h" using std::hash_map; #else #if defined ( GNUC ) && ( GNUC <= 2 ) #include <hash_map> using std::hash_map; #else #include <ext/hash_map> using gnu_cxx::hash_map; #endif #endif 13/19

Dessert ( Tricky C ++ Concepts)

Enum types Enum and int types are no more related. Thus you can no more use an int to initiate an object of type enum enum smallint { ZERO, ONE, TWO, THREE, FOUR }; smallint a = 0; enum smallint { ZERO, ONE, TWO, THREE, FOUR }; smallint a = ZERO; 15/19

Ambiguous templates In some cases template declarations can be ambiguous. int y; template <class T> void g(t& v) { T::x(y); T::z * y; } T::x could be a function call (function x declared in class T) or a variable declaration (variable y of type T::x with perverse parenthesis). T::z * could be a type or y could be multiplied by the constant T::z 16/19

Typeparams In order to resolve the ambiguity, one has to tell the compiler whether T::x is a type template <class T> void g(t& v) { typename T::x(y); } This is typically the case with containers typedef std::vector<type*> Data; typedef Data::iterator (myiterator); typedef std::vector<type*> Data; typedef typename Data::iterator (myiterator); 17/19

Why it s annoying In many cases, the compiler can resolve the ambiguity by itself (and 2.95 did). But the C ++ specification says : The typename keyword is needed whenever a type name depends on a template parameter And gcc 3.2 sticks to it typedef std::vector<type*> Data; typedef Data::iterator myiterator; typedef std::vector<type*> Data; typedef typename Data::iterator myiterator; 18/19

Conclusion You don t have to change you code I m doing it for you this week But from now you must write gcc 3.2 compatible code In order to check it, compile it under gcc 3.2 on lxplus. Tou can change compiler with these two commands : source $LHCBHOME/scripts/CMT.csh gcc32 source $LHCBHOME/scripts/CMT.csh gcc295 19/19