Struct *** initialization

This is a discussion on Struct *** initialization within the C Programming forums, part of the General Programming Boards category; >>you're saying that if you want an array of NULL pointers, you might as well just malloc it yourself and ...

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>you're saying that if you want an array of NULL pointers, you might as well just malloc it yourself and then have a loop to fill with NULLs?<<
    Yes, that is the correct method.

    >>is there any difference between
    No, but the definition of calloc says that the first parameter represents the number of elements, so for style purposes your second version is better than the first.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    While this NULL subject comes up, can we make a list of machines where NULL != all bits zero.

    Has anyone on this board actually compiled one of their programs on one of these machines?

    While we're are at it has anyone actually compiled a program on a machine where a char != 8 bits?

    Thanks.

  3. #18
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>can we make a list
    Personally, no I haven't used such a system. However, I've seen posts on here before giving specific details.

    Whatever though, the Standard says things should be done this way, so that's the way you should be learning (speaking from a generic C perspective). Remember that in the case of a NULL pointer, the actual implementation is pretty much hidden from the programmer, so unless you go using indirect pointer access to see whats in memory, you might never know.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >While this NULL subject comes up, can we make a list of machines where NULL != all bits zero.

    http://www.eskimo.com/~scs/C-faq/q5.17.html

    >While we're are at it has anyone actually compiled a program on a machine where a char != 8 bits?

    Yes.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #20
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >>While we're are at it has anyone actually compiled a program on a machine where a char != 8 bits?

    >Yes.

    Could you give details? Thanks.

  6. #21
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >Could you give details? Thanks.

    It's been a while. I believe it was for a TI DSP in the C54x family. CHAR_BIT was 16 and the sizeof char, short, and int were all 1.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Struct Initialization
    By carrotcake1029 in forum C Programming
    Replies: 5
    Last Post: 05-06-2008, 03:27 PM
  4. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  5. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21