printf() causes core dump

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon

    printf() causes core dump

    Hi,

    Can anyone tell me why this script file.c and file.h causes a core
    dump when it is compiled and run?

    Any help is appreciated.
    Sheldon

    snip....

    file.h:

    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <dirent.h>
    #include <errno.h>
    #include <ctype.h>
    #include <stdarg.h>
    #include <sys/types.h>
    #include "fort2c.h"

    #define KELEM 500
    #define KVALS 200000
    #define IBFLEN 50000

    char MODER[] = "r";
    char FILNM[] = "string_pat h";

    file.c:

    #include "file.h"

    int main() {

    int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
    int KTDLEN, KTDEXL;

    /* 1D arrays */
    int IBUFF[IBFLEN];

    char CNAMES[64][KELEM];
    char CUNITS[24][KELEM];
    char CVALS[80][KVALS];
    float VALUES[KVALS];
    int KTDLST[KELEM];
    int KTDEXP[KELEM];

    int KSEC0[8];
    int KSEC1[40];
    int KSEC2[64];
    int KEY[46];
    int KSUP[9];
    int KSEC3[4];
    int KSEC4[2];

    char ID[8];

    int i, ii;

    printf("Testing \n");

    return 1;
    }
    snip....
  • jacob navia

    #2
    Re: printf() causes core dump

    Sheldon wrote:
    Hi,
    >
    Can anyone tell me why this script file.c and file.h causes a core
    dump when it is compiled and run?
    >
    Any help is appreciated.
    Sheldon
    >

    Try to use less stack. Probably you are going beyond what
    you are allowed.

    Look at

    ulimit -a


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique

    Comment

    • Sheldon

      #3
      Re: printf() causes core dump

      On 27 Feb, 21:18, Sheldon <shejo...@gmail .comwrote:
      Hi,
      >
      Can anyone tell me why this script file.c and file.h causes a core
      dump when it is compiled and run?
      >
      Any help is appreciated.
      Sheldon
      >
      snip....
      >
      file.h:
      >
      #include <string.h>
      #include <math.h>
      #include <stdlib.h>
      #include <stdio.h>
      #include <dirent.h>
      #include <errno.h>
      #include <ctype.h>
      #include <stdarg.h>
      #include <sys/types.h>
      #include "fort2c.h"
      >
      #define KELEM 500
      #define KVALS 200000
      #define IBFLEN 50000
      >
      char MODER[] = "r";
      char FILNM[] = "string_pat h";
      >
      file.c:
      >
      #include "file.h"
      >
      int main() {
      >
        int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
        int KTDLEN, KTDEXL;
      >
        /* 1D arrays */
        int IBUFF[IBFLEN];
      >
        char  CNAMES[64][KELEM];
        char  CUNITS[24][KELEM];
        char  CVALS[80][KVALS];
        float VALUES[KVALS];
        int   KTDLST[KELEM];
        int   KTDEXP[KELEM];
      >
        int KSEC0[8];
        int KSEC1[40];
        int KSEC2[64];
        int KEY[46];
        int KSUP[9];
        int KSEC3[4];
        int KSEC4[2];
      >
        char ID[8];
      >
        int i, ii;
      >
        printf("Testing \n");
      >
        return 1;}
      >
      snip....
      Thnaks, I will try it.

      /S

      Comment

      • Martin Ambuhl

        #4
        Re: printf() causes core dump

        Sheldon wrote:
        Can anyone tell me why this script file.c and file.h causes a core
        dump when it is compiled and run?
        BTW, C is not a scripting language. Using 'script' in this context is
        likely to earn you sneers, so you might not want to do that. In any case

        #define KELEM 500
        #define KVALS 200000
        #define IBFLEN 50000
        [...]
        int main() {
        [...]
        int IBUFF[IBFLEN];
        char CNAMES[64][KELEM];
        char CUNITS[24][KELEM];
        char CVALS[80][KVALS];
        float VALUES[KVALS];
        int KTDLST[KELEM];
        int KTDEXP[KELEM];
        int KSEC0[8];
        int KSEC1[40];
        int KSEC2[64];
        int KEY[46];
        int KSUP[9];
        int KSEC3[4];
        int KSEC4[2];
        char ID[8];
        The limits on arrays guaranteed to be supported is much smaller than you
        are attempting. Even worse, you are trying to allocate them as auto
        variables. Learn to use dynamic allocation or, possibly, static arrays.
        Your subject line is completely off base: printf() has nothing to do
        with your problem. And splitting the content of your post between
        subject line and body of the message is silly. If it's worth saying,
        it's worth saying in the body of the message.

        return 1;
        1 is not a portable value for return. Worse, you are using this for
        successful completion. We know that 0 is one of the defined values for
        successful completion, the other being EXIT_SUCCESS.
        }

        Comment

        • Ben Pfaff

          #5
          Re: printf() causes core dump

          richard@cogsci. ed.ac.uk (Richard Tobin) writes:
          There's nothing wrong in principle with having large
          stack-allocated arrays.
          I am not sure that I agree. Exhaustion of automatic storage is
          not an event that a C program can detect and recover from.
          Exhaustion of dynamically allocated storage, on the other hand,
          is.
          --
          Peter Seebach on C99:
          "[F]or the most part, features were added, not removed. This sounds
          great until you try to carry a full-sized printout of the standard
          around for a day."

          Comment

          • Richard Tobin

            #6
            Re: printf() causes core dump

            In article <87pruim6r1.fsf @blp.benpfaff.o rg>,
            Ben Pfaff <blp@cs.stanfor d.eduwrote:
            >There's nothing wrong in principle with having large
            >stack-allocated arrays.
            >I am not sure that I agree. Exhaustion of automatic storage is
            >not an event that a C program can detect and recover from.
            That's true. If you're writing the kind of program where dealing
            cleanly with that is important, it would certainly make sense to
            prefer malloc().

            -- Richard
            --
            :wq

            Comment

            • CBFalconer

              #7
              Re: printf() causes core dump

              Sheldon wrote:
              >
              Can anyone tell me why this script file.c and file.h causes a core
              dump when it is compiled and run?
              You have a serious stack overflow occurring.

              --
              [mail]: Chuck F (cbfalconer at maineline dot net)
              [page]: <http://cbfalconer.home .att.net>
              Try the download section.



              --
              Posted via a free Usenet account from http://www.teranews.com

              Comment

              • Sheldon

                #8
                Re: printf() causes core dump

                On 27 Feb, 21:36, Martin Ambuhl <mamb...@earthl ink.netwrote:
                Sheldon wrote:
                Can anyone tell me why this script file.c and file.h causes a core
                dump when it is compiled and run?
                >
                BTW, C is not a scripting language.  Using 'script' in this context is
                likely to earn you sneers, so you might not want to do that.  In any case
                >
                >
                >
                >
                >
                >
                >
                #define KELEM 500
                #define KVALS 200000
                #define IBFLEN 50000
                [...]
                int main() {
                [...]
                  int IBUFF[IBFLEN];
                  char  CNAMES[64][KELEM];
                  char  CUNITS[24][KELEM];
                  char  CVALS[80][KVALS];
                  float VALUES[KVALS];
                  int   KTDLST[KELEM];
                  int   KTDEXP[KELEM];
                  int KSEC0[8];
                  int KSEC1[40];
                  int KSEC2[64];
                  int KEY[46];
                  int KSUP[9];
                  int KSEC3[4];
                  int KSEC4[2];
                  char ID[8];
                >
                The limits on arrays guaranteed to be supported is much smaller than you
                are attempting.  Even worse, you are trying to allocate them as auto
                variables.  Learn to use dynamic allocation or, possibly, static arrays.
                Your subject line is completely off base: printf() has nothing to do
                with your problem.  And splitting the content of your post between
                subject line and body of the message is silly.  If it's worth saying,
                it's worth saying in the body of the message.
                >
                  return 1;
                >
                1 is not a portable value for return.  Worse, you are using this for
                successful completion.  We know that 0 is one of the defined values for
                successful completion, the other being EXIT_SUCCESS.
                >
                >
                >
                }- Dölj citerad text -
                >
                - Visa citerad text -- Dölj citerad text -
                >
                - Visa citerad text -
                Thanks for the tips!

                Comment

                • Sheldon

                  #9
                  Re: printf() causes core dump

                  On 27 Feb, 23:42, CBFalconer <cbfalco...@yah oo.comwrote:
                  Sheldon wrote:
                  >
                  Can anyone tell me why this script file.c and file.h causes a core
                  dump when it is compiled and run?
                  >
                  You have a serious stack overflow occurring.
                  >
                  --
                   [mail]: Chuck F (cbfalconer at maineline dot net)
                   [page]: <http://cbfalconer.home .att.net>
                              Try the download section.
                  >
                  --
                  Posted via a free Usenet account fromhttp://www.teranews.co m
                  Thanks everyone for your comments, critiques, and advice.
                  I am not a programmer so I don't do this very often and hence the
                  rookie mistakes.
                  Dynamic allocating of memory works. I am grateful :)

                  /Sheldon

                  Comment

                  • Doug Miller

                    #10
                    Re: printf() causes core dump

                    In article <b2c92f54-31b3-4076-a284-22e6ba1db378@e6 0g2000hsh.googl egroups.com>, Sheldon <shejo284@gmail .comwrote:
                    >Hi,
                    >
                    >Can anyone tell me why this script file.c and file.h causes a core
                    >dump when it is compiled and run?
                    [...]
                    >#define KVALS 200000
                    [...]
                    char CVALS[80][KVALS];
                    80 * 200000 = 16MB

                    Ya think you might be running out of stack space?

                    Comment

                    • Wade Ward

                      #11
                      Re: printf() causes core dump

                      On Feb 27, 3:42 pm, CBFalconer <cbfalco...@yah oo.comwrote:
                      Sheldon wrote:
                      >
                      Can anyone tell me why this script file.c and file.h causes a core
                      dump when it is compiled and run?
                      >
                      You have a serious stack overflow occurring.
                      Gosh. Core dump. Stack trouble. Any pipes broken?

                      Oh I know ...linux.

                      Please comment further for those who aren't acquainted with whatever
                      strange reason you prefer it to windows. You're the definition of
                      topicality, Chuck.
                      --

                      Comment

                      • Micah Cowan

                        #12
                        Re: printf() causes core dump

                        Wade Ward <zaxfuuq@gmail. comwrites:
                        On Feb 27, 3:42 pm, CBFalconer <cbfalco...@yah oo.comwrote:
                        >Sheldon wrote:
                        >>
                        Can anyone tell me why this script file.c and file.h causes a core
                        dump when it is compiled and run?
                        >>
                        >You have a serious stack overflow occurring.
                        Gosh. Core dump. Stack trouble. Any pipes broken?
                        >
                        Oh I know ...linux.
                        >
                        Please comment further for those who aren't acquainted with whatever
                        strange reason you prefer it to windows. You're the definition of
                        topicality, Chuck.
                        What in the world makes you think that stack overflows aren't a
                        problem on Windows?

                        And yes, stacks are not topical here. However, it was a helpful,
                        succint, and accurate response. Which also was not particularly
                        platform-specific.

                        The mention of core dumps, of course, is more platform-specific
                        (though hardly specific to Linux). But that wasn't Chuck, that was the
                        OP.

                        --
                        Micah J. Cowan
                        Programmer, musician, typesetting enthusiast, gamer...

                        Comment

                        • Richard Tobin

                          #13
                          Re: printf() causes core dump

                          In article <fq9vfb$efj$1@n ews.xmission.co m>,
                          Kenny McCormack <gazelle@xmissi on.xmission.com wrote:
                          >In article <fq4k4u$fg7$2@p c-news.cogsci.ed. ac.uk>,
                          >Richard Tobin <richard@cogsci .ed.ac.ukwrote:
                          [...]
                          >>As Jacob indicated, there's probably a way to increase the stack
                          >>available on your system. There's nothing wrong in principle with
                          >>having large stack-allocated arrays.
                          >Note how a Clique member can say "the s-word" here and no one complains.
                          Am I a clique member? I never knew! Where do I get my badge?

                          -- Richard
                          --
                          :wq

                          Comment

                          • Kenny McCormack

                            #14
                            Re: printf() causes core dump

                            In article <fqa0cm$25jj$5@ pc-news.cogsci.ed. ac.uk>,
                            Richard Tobin <richard@cogsci .ed.ac.ukwrote:
                            >In article <fq9vfb$efj$1@n ews.xmission.co m>,
                            >Kenny McCormack <gazelle@xmissi on.xmission.com wrote:
                            >
                            >>In article <fq4k4u$fg7$2@p c-news.cogsci.ed. ac.uk>,
                            >>Richard Tobin <richard@cogsci .ed.ac.ukwrote:
                            >[...]
                            >>>As Jacob indicated, there's probably a way to increase the stack
                            >>>available on your system. There's nothing wrong in principle with
                            >>>having large stack-allocated arrays.
                            >
                            >>Note how a Clique member can say "the s-word" here and no one complains.
                            >
                            >Am I a clique member? I never knew! Where do I get my badge?
                            Dunno about the badges, but, more or less by definition, if you can say
                            the "s-word" and not get stomped on, you must be in.

                            Comment

                            • CBFalconer

                              #15
                              Re: printf() causes core dump

                              Richard Tobin wrote:
                              Kenny McCormack <gazelle@xmissi on.xmission.com wrote:
                              >Richard Tobin <richard@cogsci .ed.ac.ukwrote:
                              >
                              [...]
                              >
                              >>As Jacob indicated, there's probably a way to increase the stack
                              >>available on your system. There's nothing wrong in principle
                              >>with having large stack-allocated arrays.
                              >
                              >Note how a Clique member can say "the s-word" here and no one
                              >complains.
                              >
                              Am I a clique member? I never knew! Where do I get my badge?
                              Hold out your hand, palm down, and we will stamp it.

                              --
                              [mail]: Chuck F (cbfalconer at maineline dot net)
                              [page]: <http://cbfalconer.home .att.net>
                              Try the download section.



                              --
                              Posted via a free Usenet account from http://www.teranews.com

                              Comment

                              Working...