Sign in to follow this  
Followers 0
Jon

Coding problem

9 posts in this topic

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:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

I love stupid bugs like that. They're what makes programming worth killing yourself over. :whistle:

Share this post


Link to post
Share on other sites

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:

Share this post


Link to post
Share on other sites

I am wondering why only m_nNull dummy is initialize and not the m_sNull, m_vNull.

is the value never used? only the reference :whistle:

Share this post


Link to post
Share on other sites

if it dont work, tinker with it a bit, and maybe then it will work :whistle: lol

either that or give bill gates a call B)


~~ Safeguarding The Land ~~

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0