[huskerlug] More of a GCC problem.

  • From: "Jon Richardson" <jonpaulrichardson@xxxxxxxxxxx>
  • To: huskerlug@xxxxxxxxxxxxx
  • Date: Tue, 18 Mar 2003 09:12:03 +0000



Grr.... I'm fed up of buggy compilers, maybe it's just me? :)  Anyways I'm 
fairly new to gcc having ported my code from visual c++ 6. (Although this 
code wasn't ported from visual c++ 6)  I'm getting some strange results from 
the output of my code.

The variable iLabelNode is a variable sized array declared as such:

int iBalance = 0;
int iLabelNode[iBalance];

The variable iBalance later changes to a larger value.

Here is the code where the problem occurs:

puts("<------------- FlowGraph Crap -------------->");
        for (UINT m = 1; m <= oListLabel.Count(); ++m)
        {
                printf("%s = %d\n", oListLabel.Value(m), iLabelNode[m - 1]);
        }

        printf("iLabelNode[0] = %d\n", iLabelNode[0]);

        //get actual count
        m_iNodeCount -= iBalance;

        printf("iLabelNode[0] = %d\n", iLabelNode[0]);

        //create nodes
        Node* pNode = 0;
        for (int y = 0; y < m_iNodeCount; ++y)
        {
                pNode = new Node;
                pNodeArray[y] = pNode;
        }
        printf("iLabelNode[0] = %d\n", iLabelNode[0]);  //<-- screw up here


Can also be viewed here for pretty syntax highlighting :)
http://www.rafb.net/paste/results/P1014321.html

PORTION OF OUTPUT
<------------- FlowGraph Crap -------------->
IL_0006: = 4
IL_000e: = 6
iLabelNode[0] = 4
iLabelNode[0] = 4
iLabelNode[0] = 134587360

My question is why does the value of iLabelNode[0] change when it's clearly 
not being modified?  The funny thing is is that if I declare it as such "int 
iLableNode[100]" it works fine.  Should I just avoid variable sized arrays?  
Am I doing something stupid I don't see?

Here is what the gcc manual says about variable sized arrays, didn't say 
much but maybe I'm missing something.
http://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Variable-Length.html#Variable%20Length

If anyone could shed some light on this for me I would be very thankful, 
this is driving me nuts.

Thanks,

Jon





_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


----
Husker Linux Users Group mailing list
To unsubscribe, send a message to huskerlug-request@xxxxxxxxxxxxx
with a subject of UNSUBSCRIBE


Other related posts: