Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why does the program crash when it enters a function?

Why does the program crash when it enters a function?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structures
7 Posts 6 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaKa
    wrote on last edited by
    #1

    Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

    D N B T H 6 Replies Last reply
    0
    • K KaKa

      Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      How are you calling this function?


      "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

      "Judge not by the eye but by the heart." - Native American Proverb

      1 Reply Last reply
      0
      • K KaKa

        Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

        N Offline
        N Offline
        Nynaeve
        wrote on last edited by
        #3

        First, your crash is probably because your function is using too much stack memory. Too many local variables in the stack (or very large arrays on the stack). Second, you may want to reconsider using multi-dimensional arrays.

        1 Reply Last reply
        0
        • K KaKa

          Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

          B Offline
          B Offline
          BlitzPackage
          wrote on last edited by
          #4

          If it's crashing at the point you mentioned, it's because it is unable to successfully process the parameters. Check David Crow's comments, I think he is probably right. Also, I am not sure, but check your syntax. I am not sure if I remember correctly, but when I learned C++, I was taught that you typically pass in an array as one parameter, and the subscripts as additional parameters - or something like that, I am not sure. Anyway, you may want to use vectors instead. I hope this helps. Peace, BP

          1 Reply Last reply
          0
          • K KaKa

            Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            KaKa' wrote:

            nt rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples])

            change it to  int rank(int num,const int **data,const double *dist,const double * rank,int Tuples,int feature)

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

            1 Reply Last reply
            0
            • K KaKa

              Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              How do you use this function?

              _**


              **_

              WhiteSky


              1 Reply Last reply
              0
              • K KaKa

                Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function. I have used breakpoints and cout statements to determine the point of the crash. The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively. int rank(int num,int data[Tuples][Features], double dist[Tuples],double rank[Tuples]) { .......... ...........} The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed. I don't know what is going on. How come the program will crash without even executing a statement?

                K Offline
                K Offline
                KaKa
                wrote on last edited by
                #7

                Hi,thanks all for the replies. I think it could be a stack overflow because previously the 2D array was 128 rows by 46 columns but when I expanded it to 1600 rows, the program crashed. So, if the the function parameters are replaced by pointers instead of arrays, will the crash problem be solved? I call the rank function using this: rank(n,d,distance,r); where n is the integer variable, d is the 2D array while distance and r are the 1D arrays.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups