Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #105980

Two C code questions

From MehdiAmini <atorrses@gmail.com>
Newsgroups comp.lang.c
Subject Two C code questions
Date 2017-03-14 07:15 +0330
Organization A noiseless patient Spider
Message-ID <oa7oru$rkf$1@dont-email.me> (permalink)

Show all headers | View raw


// Clang version 3.8.0

// Question 1:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

void my_alloc( void *, size_t );

int main(void)
{
     unsigned *u_ptr = NULL;
     //unsigned *u_ptr; // Why using this instead of above line causes 
core dump?

     my_alloc(u_ptr,sizeof(*u_ptr));

     free(u_ptr);
     return EXIT_SUCCESS;
}

void my_alloc( void *v_ptr, size_t size )
{
     v_ptr = malloc(size);
     if( v_ptr == NULL )
     {
         fprintf(stderr,"Memory allocation failed.\n");
         exit(EXIT_FAILURE);
     }

     return ;
}

// Question 2:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define N 6
//static const long N = 6; // Why using this instead of above line 
causes error?

int main(void)
{
     uint64_t ui[N] = {0};

     return EXIT_SUCCESS;
}

-- 
Farewell.

Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Two C code questions MehdiAmini <atorrses@gmail.com> - 2017-03-14 07:15 +0330
  Re: Two C code questions Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-03-13 22:13 -0600
  Re: Two C code questions Ian Collins <ian-news@hotmail.com> - 2017-03-14 17:16 +1300
  Re: Two C code questions Ike Naar <ike@iceland.freeshell.org> - 2017-03-14 07:20 +0000
    Re: Two C code questions MehdiAmini <atorrses@gmail.com> - 2017-03-14 12:01 +0330
      Re: Two C code questions Ike Naar <ike@iceland.freeshell.org> - 2017-03-14 19:23 +0000
        Re: Two C code questions Keith Thompson <kst-u@mib.org> - 2017-03-14 12:40 -0700
  Re: Two C code questions scott@slp53.sl.home (Scott Lurndal) - 2017-03-14 12:44 +0000
  Re: Two C code questions Keith Thompson <kst-u@mib.org> - 2017-03-14 08:53 -0700
    Re: Two C code questions MehdiAmini <atorrses@gmail.com> - 2017-03-15 14:05 +0330
  Re: Two C code questions John Bode <jfbode1029@gmail.com> - 2017-03-14 10:38 -0700
    Re: Two C code questions Keith Thompson <kst-u@mib.org> - 2017-03-14 11:49 -0700
      Re: Two C code questions John Bode <jfbode1029@gmail.com> - 2017-03-14 14:14 -0700

csiph-web