test.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  test.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38/*
39Nov/29/00 Ulli Holtmann
40
41Assignment of values other than 0 or 1 to an sc_bit results in a core dump
42on Sparc SC5.0 as well as g++. I used SystemC 1.0.1
43
44I can understand that only 0 and 1 make sense, so please either forbid
45assignment from an integer and cast the integer to bool first. A core dump is
46a bit to drastic.
47
48Example:
49*/
50
51#include <systemc.h>
52
53int sc_main(int argc, char* arg[])
54{
55    sc_bit res;
56
57    // works fine
58    res = 0;           cout << res << "\n";
59    res = 1;           cout << res << "\n";
60    res = bool(2);     cout << res << "\n";
61
62    // results in a core dump
63    res = sc_bit(2);   cout << res << "\n";
64    res = 2;          cout << res << "\n";
65
66    return 0;
67}
68
69
70/*
71Dec/7/00 ulrich
72
73Hi Gene,
74
75I agree that the assignment of values other than 0,1 doesn't make much sense, so please go ahead
76and forbid it in one way or another. However, such an illegal assignment may easily happen in a
77user-program because the compiler accepts it. It very easy to write.
78
79The point I dislike is that the class library immediately core dumps without any warning or
80explanation. Does SystemC throw an exception? I don't know and I most likely will not write
81an exception handler, therefore I will never know. I just see that the SystemC kernel core
82dumps.
83
84What about an assert statement such like
85	assert(v==0 || v==1);
86That should me as the user a precise and reasonable explanation that I made a mistake. I could
87also accept an error message like E200x or so coming like when I enter illlegal bit characters,
88e.g. sc_bv<10>="102abd00". But please, not just a core dump.
89
90
91
92Jan/9/01 ulrich
93
94Hi Gene, I still only ask that the program does not core dump and instead prints an error
95message or warning like it does for sc_logic. I only object to the core dump itself. Example:
96
97
98int main(int argc, char* arg[])
99{
100  sc_logic l (5);
101  cout << l << "\n";
102
103  sc_bit b(2);
104  cout << b << "\n";
105}
106
107Both are invalid assignments. The first one prompt a warning (1006), the second a core
108dump. Both should prompt warnings/run time errors.
109
110I reduce the prioity to B2 because it's now only a matter of properly reporting an error.
111
112Other than
113this, I can share your view that assigning 2 is a user error.
114*/
115