0

In a constructor:

CSVBMFBlockModelReader(const wchar_t * const FileNameWithPath, char Delimiter)
{
    _FileNameWithPath = FileNameWithPath;
    _Delimiter = Delimiter;
}

Intellisense then reports {npos=18446744073709551615 } and the Immediate Window reports something similiar:

{npos=18446744073709551615 } (error): 0 (error): 0

Am I doing something wrong or is this just intellisense? The code works as expected and _FileNameWithPath.data() returns the correct result. The compiler issues no warning of any kind. The local private declarations are:

private:

    std::wstring _FileNameWithPath;
    char _Delimiter;

I must state that I am debugging the code after launching it from c#. I am using VS 2015 Enterprise.

Please note I am aware that 0XFFFFFFFFFFFFFFFF is the same value. My interest is in why intellisense displays this value to me.

Peter
  • 393
  • 3
  • 15
  • How are you launching it from C#? – Tanveer Badar Aug 02 '17 at 11:54
  • What is `npos`? – CinCout Aug 02 '17 at 11:55
  • @Tanveer Badar [DllImport(DLLName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, EntryPoint = "ReadVulcanCSVFileHeader")] public static extern void ReadVulcanCSVFileHeader([In] string FileNameWithPath, ref uint FieldCount, FeedBack FeedBack, ref int ErrorCode); – Peter Aug 02 '17 at 11:56
  • 1
    18446744073709551615 is 0xFFFFFFFFFFFFFFFF which is -1 interpreted as an unsigned integer. It sounds like a type mismatch or uninitialized value. However, the code you're showing seems to have nothing to do with the error you're reporting so this question is not exactly answerable. – Jonathon Reinhart Aug 02 '17 at 11:56
  • @JonathonReinhart I am hoping that someone may be able to confirm that they have also had the same experience and have concluded this is not a problem. – Peter Aug 02 '17 at 11:58
  • @Code Gray No, I am not asking why 0XFFFFFFFFFFFFFFFF is the value that it is. I am asking why intellisense does not display something useful instead of what it did display. In particular is this an indication of an error of some kind? – Peter Aug 02 '17 at 12:04
  • FYI: You got my name wrong, so the ping didn't actually work. I just happened to have this tab still open where I could see your reply. Anyway, I don't understand where your confusion persists. Intellisense is displaying this long integer value because it's equivalent to -1 as an unsigned integer. You say you already know that. The `npos` field is -1 because that's the default value for that field. It's only an error if you had just previously called a member function that performs a search or otherwise looks for a position; in that case, it would indicate no valid position was found. – Cody Gray - on strike Aug 02 '17 at 12:46

1 Answers1

1

You're just seeing a part of std::string/std::wstring. std::string::npos is a sentinel value and is used to indicate when a member function doesn't find a valid position in the string. It is defined as

size_type npos = -1;

and since size_type is a unsigned integer type it wraps around to be the largest number that type can hold. In this case you are seeing the maximum value a 64 bit unsigned integer can hold.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402