Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could be a proper data type for software version in C++?

Tags:

c++

types

version

I need to declare a field call "version", but am not sure what data type to use.

My "version" is something like "11.04". I am considering "double" as a good candidate.

like image 754
Terry Li Avatar asked Dec 01 '22 07:12

Terry Li


2 Answers

Use two ints - one for the major version number and one for the minor one. Alternatively, use a string :) A double doesn't sound like a good candidate because a lot of numbers can't be represented exactly by doubles.

like image 43
Stuart Golodetz Avatar answered Feb 17 '23 21:02

Stuart Golodetz


double is probably a bad idea, unless you are planning on using a Knuth-style version converging on an irrational number. What's wrong with an array of int, or a character string?

like image 153
James McLeod Avatar answered Feb 17 '23 21:02

James McLeod