OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [doc/] [xml/] [manual/] [support.xml] - Blame information for rev 519

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
2
3
 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
4
[ ]>
5
 
6
7
8
 
9
10
  
11
    
12
      ISO C++
13
    
14
    
15
      library
16
    
17
  
18
19
 
20
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>21</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Support</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>22</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  <indexterm><primary>Support</primary></indexterm></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>23</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
24
 
25
  
26
    This part deals with the functions called and objects created
27
    automatically during the course of a program's existence.
28
  
29
 
30
  
31
    While we can't reproduce the contents of the Standard here (you
32
    need to get your own copy from your nation's member body; see our
33
    homepage for help), we can mention a couple of changes in what
34
    kind of support a C++ program gets from the Standard Library.
35
  
36
 
37
38
  
39
  Types
40
  
41
    Fundamental Types
42
    
43
      C++ has the following builtin types:
44
    
45
    
46
      
47
        char
48
      
49
      
50
        signed char
51
      
52
      
53
        unsigned char
54
      
55
      
56
        signed short
57
      
58
      
59
        signed int
60
      
61
      
62
        signed long
63
      
64
      
65
        unsigned short
66
      
67
      
68
        unsigned int
69
      
70
      
71
        unsigned long
72
      
73
      
74
        bool
75
      
76
      
77
        wchar_t
78
      
79
      
80
        float
81
      
82
      
83
        double
84
      
85
      
86
        long double
87
      
88
    
89
 
90
    
91
      These fundamental types are always available, without having to
92
      include a header file. These types are exactly the same in
93
      either C++ or in C.
94
    
95
 
96
    
97
      Specializing parts of the library on these types is prohibited:
98
      instead, use a POD.
99
    
100
 
101
  
102
  
103
    Numeric Properties
104
 
105
 
106
    
107
    The header limits defines
108
    traits classes to give access to various implementation
109
    defined-aspects of the fundamental types. The traits classes --
110
    fourteen in total -- are all specializations of the template class
111
    numeric_limits, documented 
112
    url="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00593.html">here
113
    and defined as follows:
114
    
115
 
116
   
117
   template<typename T>
118
     struct class
119
     {
120
       static const bool is_specialized;
121
       static T max() throw();
122
       static T min() throw();
123
 
124
       static const int digits;
125
       static const int digits10;
126
       static const bool is_signed;
127
       static const bool is_integer;
128
       static const bool is_exact;
129
       static const int radix;
130
       static T epsilon() throw();
131
       static T round_error() throw();
132
 
133
       static const int min_exponent;
134
       static const int min_exponent10;
135
       static const int max_exponent;
136
       static const int max_exponent10;
137
 
138
       static const bool has_infinity;
139
       static const bool has_quiet_NaN;
140
       static const bool has_signaling_NaN;
141
       static const float_denorm_style has_denorm;
142
       static const bool has_denorm_loss;
143
       static T infinity() throw();
144
       static T quiet_NaN() throw();
145
       static T denorm_min() throw();
146
 
147
       static const bool is_iec559;
148
       static const bool is_bounded;
149
       static const bool is_modulo;
150
 
151
       static const bool traps;
152
       static const bool tinyness_before;
153
       static const float_round_style round_style;
154
     };
155
   
156
  
157
 
158
  
159
    NULL
160
    
161
     The only change that might affect people is the type of
162
     NULL: while it is required to be a macro,
163
     the definition of that macro is not allowed
164
     to be (void*)0, which is often used in C.
165
    
166
 
167
    
168
     For g++, NULL is
169
     #define'd to be
170
     __null, a magic keyword extension of
171
     g++.
172
    
173
 
174
    
175
     The biggest problem of #defining NULL to be
176
     something like 0L is that the compiler will view
177
     that as a long integer before it views it as a pointer, so
178
     overloading won't do what you expect. (This is why
179
     g++ has a magic extension, so that
180
     NULL is always a pointer.)
181
    
182
 
183
    In his book 
184
    url="http://www.awprofessional.com/titles/0-201-92488-9/">Effective
185
    C++, Scott Meyers points out that the best way
186
    to solve this problem is to not overload on pointer-vs-integer
187
    types to begin with.  He also offers a way to make your own magic
188
    NULL that will match pointers before it
189
    matches integers.
190
    
191
    See
192
      the
193
      Effective C++ CD example
194
    
195
  
196
 
197
198
 
199
200
  
201
  Dynamic Memory
202
  
203
    There are six flavors each of new and
204
    delete, so make certain that you're using the right
205
    ones. Here are quickie descriptions of new:
206
  
207
  
208
      
209
        single object form, throwing a
210
        bad_alloc on errors; this is what most
211
        people are used to using
212
      
213
      
214
        Single object "nothrow" form, returning NULL on errors
215
      
216
      
217
        Array new, throwing
218
        bad_alloc on errors
219
      
220
      
221
        Array nothrow new, returning
222
        NULL on errors
223
      
224
      
225
        Placement new, which does nothing (like
226
        it's supposed to)
227
      
228
      
229
        Placement array new, which also does
230
        nothing
231
      
232
   
233
   
234
     They are distinguished by the parameters that you pass to them, like
235
     any other overloaded function.  The six flavors of delete
236
     are distinguished the same way, but none of them are allowed to throw
237
     an exception under any circumstances anyhow.  (They match up for
238
     completeness' sake.)
239
   
240
   
241
     Remember that it is perfectly okay to call delete on a
242
     NULL pointer!  Nothing happens, by definition.  That is not the
243
     same thing as deleting a pointer twice.
244
   
245
   
246
     By default, if one of the throwing news can't
247
     allocate the memory requested, it tosses an instance of a
248
     bad_alloc exception (or, technically, some class derived
249
     from it).  You can change this by writing your own function (called a
250
     new-handler) and then registering it with set_new_handler():
251
   
252
   
253
   typedef void (*PFV)(void);
254
 
255
   static char*  safety;
256
   static PFV    old_handler;
257
 
258
   void my_new_handler ()
259
   {
260
       delete[] safety;
261
       popup_window ("Dude, you are running low on heap memory.  You
262
                      should, like, close some windows, or something.
263
                      The next time you run out, we're gonna burn!");
264
       set_new_handler (old_handler);
265
       return;
266
   }
267
 
268
   int main ()
269
   {
270
       safety = new char[500000];
271
       old_handler = set_new_handler (&my_new_handler);
272
       ...
273
   }
274
   
275
   
276
     bad_alloc is derived from the base exception
277
     class defined in Sect1 19.
278
   
279
280
 
281
282
  
283
  Termination
284
  
285
    Termination Handlers
286
    
287
      Not many changes here to 
288
      class="headerfile">cstdlib.  You should note that the
289
      abort() function does not call the
290
      destructors of automatic nor static objects, so if you're
291
      depending on those to do cleanup, it isn't going to happen.
292
      (The functions registered with atexit()
293
      don't get called either, so you can forget about that
294
      possibility, too.)
295
    
296
    
297
      The good old exit() function can be a bit
298
      funky, too, until you look closer.  Basically, three points to
299
      remember are:
300
    
301
    
302
      
303
        
304
        Static objects are destroyed in reverse order of their creation.
305
        
306
      
307
      
308
        
309
        Functions registered with atexit() are called in
310
        reverse order of registration, once per registration call.
311
        (This isn't actually new.)
312
        
313
      
314
      
315
        
316
        The previous two actions are interleaved, that is,
317
        given this pseudocode:
318
        
319
320
  extern "C or C++" void  f1 (void);
321
  extern "C or C++" void  f2 (void);
322
 
323
  static Thing obj1;
324
  atexit(f1);
325
  static Thing obj2;
326
  atexit(f2);
327
328
        
329
        then at a call of exit(),
330
        f2 will be called, then
331
        obj2 will be destroyed, then
332
        f1 will be called, and finally
333
        obj1 will be destroyed. If
334
        f1 or f2 allow an
335
        exception to propagate out of them, Bad Things happen.
336
        
337
      
338
    
339
    
340
      Note also that atexit() is only required to store 32
341
      functions, and the compiler/library might already be using some of
342
      those slots.  If you think you may run out, we recommend using
343
      the xatexit/xexit combination from libiberty, which has no such limit.
344
    
345
  
346
 
347
  
348
  
349
    Verbose Terminate Handler
350
    
351
      If you are having difficulty with uncaught exceptions and want a
352
      little bit of help debugging the causes of the core dumps, you can
353
      make use of a GNU extension, the verbose terminate handler.
354
    
355
 
356
357
#include <exception>
358
 
359
int main()
360
{
361
  std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
362
  ...
363
 
364
  throw anything;
365
}
366
367
 
368
   
369
     The __verbose_terminate_handler function
370
     obtains the name of the current exception, attempts to demangle
371
     it, and prints it to stderr.  If the exception is derived from
372
     exception then the output from
373
     what() will be included.
374
   
375
 
376
   
377
     Any replacement termination function is required to kill the
378
     program without returning; this one calls abort.
379
   
380
 
381
   
382
     For example:
383
   
384
 
385
386
#include <exception>
387
#include <stdexcept>
388
 
389
struct argument_error : public std::runtime_error
390
{
391
  argument_error(const std::string& s): std::runtime_error(s) { }
392
};
393
 
394
int main(int argc)
395
{
396
  std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
397
  if (argc > 5)
398
    throw argument_error(argc is greater than 5!);
399
  else
400
    throw argc;
401
}
402
403
 
404
   
405
     With the verbose terminate handler active, this gives:
406
   
407
 
408
   
409
   
410
   % ./a.out
411
   terminate called after throwing a `int'
412
   Aborted
413
   % ./a.out f f f f f f f f f f f
414
   terminate called after throwing an instance of `argument_error'
415
   what(): argc is greater than 5!
416
   Aborted
417
   
418
   
419
 
420
   
421
     The 'Aborted' line comes from the call to
422
     abort(), of course.
423
   
424
 
425
   
426
     This is the default termination handler; nothing need be done to
427
     use it.  To go back to the previous silent death
428
     method, simply include exception and
429
     cstdlib, and call
430
   
431
 
432
   
433
     std::set_terminate(std::abort);
434
   
435
 
436
   
437
     After this, all calls to terminate will use
438
     abort as the terminate handler.
439
   
440
 
441
   
442
     Note: the verbose terminate handler will attempt to write to
443
     stderr.  If your application closes stderr or redirects it to an
444
     inappropriate location,
445
     __verbose_terminate_handler will behave in
446
     an unspecified manner.
447
   
448
 
449
  
450
451
 
452

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.