Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SizeAssert.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 
00003 // This file is part of Vesta.
00004 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Sat May 29 14:09:08 EDT 2004 by ken@xorian.net
00020 
00021 #include <iostream>     // cerr
00022 #include <stdlib.h>     // abort
00023 #include <assert.h>     // assert
00024 
00025 #include "SizeAssert.H"
00026 
00027 using std::cerr;
00028 using std::endl;
00029 
00030 // sizeof_assert_fail:
00031 
00032 // Handle a sizeof assertion.  Assume that the actual size doesn't
00033 // match the expected size (if not, this function won't be called).
00034 // Print a message to standard error.  Optionally, abort execution
00035 // (which usually results in a core dump as well).
00036 
00037 // Parameters:
00038 
00039 //   typ:      a string representation of the type
00040 //   gotsize:  the actual size of the type
00041 //   targsize: the expected size
00042 //   fname:    the source file name of the sizeof assertion
00043 //   line:     the source file line of the sizeof assertion
00044 //   die:      should we abort?
00045 
00046 void sizeof_assert_fail(const char * typ,
00047                         unsigned long gotsize, unsigned long targsize,
00048                         const char * fname, unsigned int line,
00049                         bool die)
00050 {
00051   // The only way we should get here is if we got a size other than
00052   // what we expected.
00053   assert(gotsize != targsize);
00054 
00055   // Issue a message about it
00056   cerr << "Bad size for type '" << typ << "': got " << gotsize
00057        << ", expected " << targsize
00058        << " at " << fname << ":" << line << endl;
00059 
00060   // If we are supposed to abort on a size mismatch (the same thing as
00061   // a failed assertion), do so.
00062   if(die)
00063     {
00064       abort();
00065     }
00066 }

Generated on Mon May 8 00:48:28 2006 for Vesta by  doxygen 1.4.2