Segfault on new?

Discussion in 'C++' started by Scoots, Sep 30, 2008.

  1. Scoots

    Scoots Guest

    Okay, I have a really simple program that illustrates a problem I'm
    having.

    I'm using VC++6.0 (yes, an upgrade is in the works). Anywho, I have
    this problem:


    int main (int argc, char * argv[])
    {
    int iNumFuncs = 1;
    int * hey = new int [iNumFuncs]; <<--Segfaults. ??????
    return 0;
    }


    Is my installation just gone out the window, or am I so incredibly
    tired that I can't even do a dynamic allocation anymore?
     
    Scoots, Sep 30, 2008
    #1
    1. Advertising

  2. Scoots

    Scoots Guest

    On Sep 30, 5:54 pm, Victor Bazarov <> wrote:
    > Scoots wrote:
    > > Okay, I have a really simple program that illustrates a problem I'm
    > > having.

    >
    > > I'm using VC++6.0 (yes, an upgrade is in the works). Anywho, I have
    > > this problem:

    >
    > > int main (int argc, char * argv[])
    > > {
    > > int iNumFuncs = 1;
    > > int * hey = new int [iNumFuncs]; <<--Segfaults. ??????
    > > return 0;
    > > }

    >
    > > Is my installation just gone out the window, or am I so incredibly
    > > tired that I can't even do a dynamic allocation anymore?

    >
    > The code seems OK (the memory leak is beside the point, I guess). If
    > you need your question answered with VC++ in mind, then you need to ask
    > it in the VC++ newsgroup, though: microsoft.public.vc.language.
    >
    > There can be some compiler specific settings that are off-topic here,
    > try the other newsgroup and see what they say...
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask- Hide quoted text -
    >
    > - Show quoted text -


    Well, the memory leak is kinda irrelevant, I just commented out the
    few hundred other lines in the code and didn't bother posting them
    here. There IS a delete[], it's just commented out.

    And I didn't think this was a VC++ question in particular, since I'm
    not using a single call to anything relating to VC++. What I posted
    should be standard c++ in it's entirety.

    My question, is what can be causing that. And I believe your answer
    was: "Compiler."

    Thanks,
    ~Scoots.

    (P.S. I appologize for any seeming rudeness, it is unintentional.)
     
    Scoots, Sep 30, 2008
    #2
    1. Advertising

  3. Scoots wrote:

    >
    >
    > On Sep 30, 5:54 pm, Victor Bazarov <> wrote:
    >> Scoots wrote:
    >> > Okay, I have a really simple program that illustrates a problem I'm
    >> > having.

    >>
    >> > I'm using VC++6.0 (yes, an upgrade is in the works). Anywho, I have
    >> > this problem:

    >>
    >> > int main (int argc, char * argv[])
    >> > {
    >> > int iNumFuncs = 1;
    >> > int * hey = new int [iNumFuncs]; <<--Segfaults. ??????
    >> > return 0;
    >> > }

    >>
    >> > Is my installation just gone out the window, or am I so incredibly
    >> > tired that I can't even do a dynamic allocation anymore?

    >>
    >> The code seems OK (the memory leak is beside the point, I guess). If
    >> you need your question answered with VC++ in mind, then you need to ask
    >> it in the VC++ newsgroup, though: microsoft.public.vc.language.
    >>
    >> There can be some compiler specific settings that are off-topic here,
    >> try the other newsgroup and see what they say...
    >>
    >> V
    >> --
    >> Please remove capital 'A's when replying by e-mail
    >> I do not respond to top-posted replies, please don't ask- Hide quoted
    >> text -
    >>
    >> - Show quoted text -

    >
    > Well, the memory leak is kinda irrelevant, I just commented out the
    > few hundred other lines in the code and didn't bother posting them
    > here. There IS a delete[], it's just commented out.
    >
    > And I didn't think this was a VC++ question in particular, since I'm
    > not using a single call to anything relating to VC++. What I posted
    > should be standard c++ in it's entirety.
    >
    > My question, is what can be causing that. And I believe your answer
    > was: "Compiler."
    >
    > Thanks,
    > ~Scoots.
    >
    > (P.S. I appologize for any seeming rudeness, it is unintentional.)


    I don't use arrays much, so the syntax is a bit unfamiliar to me. However,
    its working fine here with gcc version 4.3.1 on OpenSUSE 11.0

    int main (int argc, char * argv[])
    {
    int iNumFuncs = 1;
    int * hey = new int [iNumFuncs]; //  <<--Segfaults.   ??????
    hey[0] = 99;
    cout << "hey = " << hey << " hey[0] = " << hey[0] << endl;
    return 0;
    }

    Output: hey = 0x804b008 hey[0] = 99

    Chris Gordon-Smith
    www.simsoup.info
     
    Chris Gordon-Smith, Oct 1, 2008
    #3
  4. Scoots

    Rolf Magnus Guest

    Scoots wrote:

    > On Sep 30, 5:54 pm, Victor Bazarov <> wrote:
    >> Scoots wrote:
    >> > Okay, I have a really simple program that illustrates a problem I'm
    >> > having.

    >>
    >> > I'm using VC++6.0 (yes, an upgrade is in the works). Anywho, I have
    >> > this problem:

    >>
    >> > int main (int argc, char * argv[])
    >> > {
    >> > int iNumFuncs = 1;
    >> > int * hey = new int [iNumFuncs]; <<--Segfaults. ??????
    >> > return 0;
    >> > }

    >>
    >> > Is my installation just gone out the window, or am I so incredibly
    >> > tired that I can't even do a dynamic allocation anymore?

    >>
    >> The code seems OK (the memory leak is beside the point, I guess). If
    >> you need your question answered with VC++ in mind, then you need to ask
    >> it in the VC++ newsgroup, though: microsoft.public.vc.language.
    >>
    >> There can be some compiler specific settings that are off-topic here,
    >> try the other newsgroup and see what they say...

    >
    > Well, the memory leak is kinda irrelevant, I just commented out the
    > few hundred other lines in the code and didn't bother posting them
    > here. There IS a delete[], it's just commented out.
    >
    > And I didn't think this was a VC++ question in particular, since I'm not

    using a single call to anything relating to VC++.

    Your question wasn't specific to VC++. It was fine, but cannot be answered
    here.

    > What I posted should be standard c++ in it's entirety.


    Yes, it is.

    > My question, is what can be causing that. And I believe your answer
    > was: "Compiler."


    Yes. Regarding standard C++, your code is - as far as I can see - correct,
    so it must be some compiler issue. And for that, a VC++ group will be more
    appropriate.
     
    Rolf Magnus, Oct 1, 2008
    #4
  5. Scoots

    Scoots Guest

    Indeed, this was the code, minus a few thousand lines that were
    essentially commented out (the calls to other files/functions) which
    is why I took out the includes. But I had yes, actually reduced my
    main to that through commenting out code.

    And yes, it wasn't a true segfault :)

    Too many years in school to take segfault out of my vocabulary though!

    I took your advice and asked over there and the issue has been...
    well, avoided if not resolved.
     
    Scoots, Oct 3, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vedran Vyroubal

    STL string segfault

    Vedran Vyroubal, Mar 3, 2004, in forum: C++
    Replies:
    5
    Views:
    1,382
    Vedran Vyroubal
    Mar 4, 2004
  2. Arthur J. O'Dwyer

    multiset segfault

    Arthur J. O'Dwyer, Jun 17, 2004, in forum: C++
    Replies:
    10
    Views:
    752
    Dave Townsend
    Jun 18, 2004
  3. Jim Strathmeyer

    istream segfault

    Jim Strathmeyer, Jul 22, 2004, in forum: C++
    Replies:
    4
    Views:
    453
    Mike Wahler
    Jul 23, 2004
  4. Andrey Vul
    Replies:
    8
    Views:
    710
    Richard Bos
    Jul 30, 2010
  5. Replies:
    2
    Views:
    502
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page