[Gllug] c / sizeof structures / tool

Simon Trimmer simon at urbanmyth.org
Sat Jun 15 01:10:05 UTC 2002


Yeah, well, I was looking for a quick fix and the list was found to be
wanting in knowledge! :)

I could build a new a set of rules and use the C preprocessor to throw away
everything except structures, crank the handle and have it spit out their
size but I have more pressing technical challenges....

-Simon

On Sat, 15 Jun 2002, Jonathan Harker wrote:
> On Friday 14 June 2002 6:31 pm, Simon Trimmer wrote:
> > Someone must know this...
> >
> > Given a load of .h files, does anyone know of a tool to display the size of
> > the structures?
> >
> > -Simon
> > Simon Trimmer <simon at urbanmyth.org>
> >
>
> <disclaimer>
> I do not know of any available tools.
> I am NOT a perl head.
> I am pissed.
> It is late.
> </disclaimer>
>
> You could write a shell/perl/other script that writes and compiles a little
> program for each .h you have. For each .h, look for (awk?) a sequence such as
>
> struct X
> class Y
>
> and record and count the class/struct names. You don't want the ones that end
> in semicolons as they're declared without being defined, eg.
>
> struct DefinedElsewhere;
>
> Once you've miraculously got the list of class/struct names, generate a
> test.cpp file along the lines of
>
> ----------
> #include <iostream>
> using std::cout;
> using std::endl;
>
> // your script inserts the header file here:
> #include <header.h>
> int main()
> {
>   // get your script to automate this for each class/struct name:
>   cout << "X has a size of " << sizeof(X) << endl;
>   cout << "Y has a size of " << sizeof(Y) << endl;
> }
> ----------
>
> Then compile it
> (g++ -o test test.cpp)
> and run the test program...
> repeat for each .h
>
> Hope that helps, bear in mind above disclaimer!
> Luv Jon
>
> --
> Jonathan Harker
> Web: www.jonathanharker.co.uk
> ICQ: 30647378
> MSN Messenger: jonathanischoice at hotmail.com
> Yahoo & AIM chat: jonathanischoice
>
> --
> Gllug mailing list  -  Gllug at linux.co.uk
> http://list.ftech.net/mailman/listinfo/gllug
>


-Simon
Simon Trimmer <simon at urbanmyth.org>


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list