有没有办法在C ++中定义异常的整数大小?

时间:2015-06-22 19:43:41

标签: c++

我可以使用:Dim x As Long Dim y As Long Dim CDTotal As Double Dim CSTotal As Double Dim ETotal As Double Dim FTotal As Double Dim HTotal As Double Dim ITotal As Double Dim ITTotal As Double Dim MTotal As Double Dim TTotal As Double Dim UTotal As Double Dim TotalValue As Double For y = 3 To 3 For x = 600 To 1 Step -1 If Cells(x, y).Value = "CD Sector Average" Then CDTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "CS Sector Average" Then CSTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "E Sector Average" Then ETotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "F Sector Average" Then FTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "H Sector Average" Then HTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "I Sector Average" Then ITotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "IT Sector Average" Then ITTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "M Sector Average" Then MTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "T Sector Average" Then TTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "U Sector Average" Then UTotal = Cells(x, y + 5).Value End If If Cells(x, y).Value = "Total Portfolio" Then TotalValue = UTotal + TTotal + MTotal + ITTotal + ITotal + HTotal + FTotal + ETotal + CSTotal + CDTotal Cells(x, y + 5) = TotalValue End If Next x Next y std::int8_t等在C ++中定义不同大小的整数值。有没有办法定义一个使用14位的整数?

3 个答案:

答案 0 :(得分:3)

你在找bitfield吗? 在这个例子中,y取14位这是我能想到的最接近的匹配

struct x
{
    int y :14 ;
} ;

答案 1 :(得分:1)

您可以创建一个与std :: uint14_t完全相同的类(如果存在)。由于任何不适合签名类型的值都会调用未定义的行为,因此typedef std :: int16_t int14_t非常好。

答案 2 :(得分:0)

没有。阅读所有评论和其他答案,以澄清原因。