Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

STL warning messages

I am trying to compile this simple program I got from one
of the STL tutorail sites. The program compiles and runs, but I get a lot of warning messages which I simply do not want to ignore, but can't find a explanation. I am using MS VC++ 4.0. Here is the program:

#include <map.h>
#include <iostream.h>
#include <string.h>



struct ltstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) < 0;
  }
};

void main()
{
  map<const char*, int, ltstr > months;
 
  months["january"] = 31;
  months["february"] = 28;
  months["march"] = 31;
  months["april"] = 30;
  months["may"] = 31;
  months["june"] = 30;
  months["july"] = 31;
  months["august"] = 31;
  months["september"] = 30;
  months["october"] = 31;
  months["november"] = 30;
  months["december"] = 31;
 
  cout << "june -> " << months["june"] << endl;
  map<const char*, int, ltstr>::iterator cur  = months.find("june");
  map<const char*, int, ltstr>::iterator prev = cur;
  map<const char*, int, ltstr>::iterator next = cur;    
  ++next;
  --prev;
  cout << "Previous (in alphabetical order) is " << (*prev).first << endl;
  cout << "Next (in alphabetical order) is " << (*next).first << endl;
}

Here are the error messages:
Compiling...
Text1.cpp
D:\development\c\stl\Text1.cpp(40) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator,rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator>' : identifier was truncated to '255' characters in the debug information
D:\MSDEV\STL\tree.h(840) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator,rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator>' : identifier was truncated to '255' characters in the debug information
D:\MSDEV\STL\tree.h(840) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator,rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator' : identifier was truncated to '255' characters in the debug information
D:\MSDEV\STL\tree.h(840) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator,rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator>' : identifier was truncated to '255' characters in the debug information
D:\MSDEV\STL\pair.h(26) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::iterator,int>::pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::iterator,int>' : identifier was truncated to '255' characters in the debug information
D:\MSDEV\STL\defalloc.h(78) : warning C4786: 'pair<rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator,rb_tree<char const *,pair<char const * const,int>,select1st<pair<char const * const,int>,char const *>,ltstr>::const_iterator>' : identifier was truncated to '255' characters in the debug information
Text1.obj - 0 error(s), 6 warning(s)

What is going on here?
0
misha051797
Asked:
misha051797
1 Solution
 
yonatCommented:
The Visual C++ debugger has problems with identifier longet than 255 characters, so the compiler trucncates such identifiers. This is harmless. Add the line
    #pragma warning (disable : 4786)
in the beginning of the file to avoid seeing these warnings, and rebuild all (so that the precompiled headers will also get rebuilt).
0
 
paynCommented:
If you're using a "StdAfx.h" or similar file that is always included first in all .cpp files, and specifies all of your precompiled headers, make sure to put the #pragma in that file, not just in each file that #includes <map> or whatever. Otherwise the warning may still appear.

I think the problem's actually in the file format. While Microsoft uses COFF for object files, rather than the COFF debugger format, they use their own. I have no idea why. And I think that the debugger labels in their format are Pascal-style length-first strings with one-byte lengths.

Of course the debugger can't display 255 character types or other identifiers in the vast majority of places anyway. It has some problems with word wrap, and in a few places it stores identifiers in an 80-byte slot, and in general the GUI design doesn't give enough space for really long names.

Anyway, because the compiler truncates the names, when the debugger goes to look for names it won't find them. This is why you get that scary warning saying "The debugger cannot debug code with symbols longer than 255 characters. In the debugger, you cannot view, evaluate, update, or watch the truncated symbols."

Well, if you have a variable or function whose unqualified name is over 255 characters, then yes, you're in trouble. But if you have a variable or function whose type is over 255 characters, everything will be fine, even though you get the same warning.

Nearly every time you use a map, you'll get a typename over 255 characters, and you'll get this warning, but you'll never notice any problems if you disable it.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now