Jump to content

Coding problem


Jon
 Share

Recommended Posts

  • Administrators

Can anyone see why this would work:

MessageBox(NULL, vParams[0].szValue(), "", MB_OK);

but this doesn't:

const char *szValue = vParams[0].szValue();
MessageBox(NULL, szValue, "", MB_OK);

Given that .szValue() returns "const char *"

:iamstupid:

Link to comment
Share on other sites

Very strange. I say blame Microsoft just because it's fun. :whistle:

Have you re-written any of the Variant or VectorVariant code since 3.0.76? That's the last copy of the source I have downloaded so it's the one I looked at. Using it for reference, I see no reason why that code won't work (For what my opinions worth, I probably have less programming experience than all of you). Could it maybe have something to do with the subscripting operator? I threw together a simple class where a function returned a const char* to a dynamically allocated array and I experienced no abnormalities. The only thing I didn't test was subscripting. :: shrugs ::

:iamstupid: :iamstupid:

Edited by Valik
Link to comment
Share on other sites

  • Administrators

Hmm, I thought it was odd too so am just trying to work out if it's like you say a subscript bug.

This works, so it looks like the variant creation, assignment and copy constructors are working ok:

const char *pszValue;
    Variant vTest;
    vTest = "Hello";

    MessageBox(NULL, vTest.szValue(), "", MB_OK);
    pszValue = vTest.szValue();
    MessageBox(NULL, pszValue, "", MB_OK);

    Variant vTestCopy(vTest);
    MessageBox(NULL, vTestCopy.szValue(), "", MB_OK);
    pszValue = vTestCopy.szValue();
    MessageBox(NULL, pszValue, "", MB_OK);

    vTestCopy = vTest;
    MessageBox(NULL, vTestCopy.szValue(), "", MB_OK);
    pszValue = vTestCopy.szValue();
    MessageBox(NULL, pszValue, "", MB_OK);

Link to comment
Share on other sites

  • Administrators

All my stacks, vectors, tokens everything had the same declaration, and while not technically a bug I'm now returning references everywhere instead of these temporary "copies".

Result:

- Everything is faster (less copying)

- Uncompressed EXE reduced by 30KB! (78KB compressed)

- All vectors can be modifed as well as just read: e.g. vParams[0] = ...

This is one of those times I realise how complicated C++ can be... :whistle:

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...