Menu

Improving vec Debug

2004-12-15
2012-09-15
  • Michael Kreeger

    Michael Kreeger - 2004-12-15

    I have a suggestion to improve debugging. When I use a vec with a pointer sometimes I misstakenly write out of bounds. In debug I have added FILE and LINE to the it_assert0() call. This will tell me the line number and file of my code as well as the itpp code.

    Here is an example of the change that I made:

    file vec.h line 239

    inline Num_T &operator()(int i) { it_assert0(i>=0&&i<datasize, "operator() F:"<<__FILE__<<" L:"<<__LINE__); return data[i]; }
    

    Anyone have any other suggestions?

    Michael

     
    • don camillo

      don camillo - 2005-01-20

      I think it is a very good idea as probably the most common cause of troubles is running out of vector indexes. I tried your patch using GCC 3.4.3. Unfortunately this will not compile in this form. The compiler complains about the << operators. I assume this is because, as I read somewhere, starting from GCC 3.4.0 FILE, LINE and the like are treated as regular variables instead of preprocessor substitutions. Probably it_assert_f must be then altered to accept more than two arguments (?).
      But I'm still very interested in such a solution which enables your idea under GCC 3.4 :)

       
      • Tony Ottosson Gadd

        Hi,

        I have tested the proposed scheme on gcc 3.3.3 on I do not get it to work. Furthermore, rewriting the assert to a cout instead using FILE and LINE only give error report to vec.h and the corresponding line. Hence, I cannot see that we can solve this problem. It would have been nice, though.

        /Tony

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.