Doubt if this is bad pointer

This is a discussion on Doubt if this is bad pointer within the C Programming forums, part of the General Programming Boards category; Hello I'm wondering if this pointer is bad. I saw this example in a book. The structure allocates the memory ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    Doubt if this is bad pointer

    Hello I'm wondering if this pointer is bad. I saw this example in a book.

    The structure allocates the memory for the pointer?

    Ty

    Code:
    struct KeyWord {
      char *word; // This is bad????
      int counter;
    } key_words[] = {
      {"int", 0},
      {"break", 0},
      {"case", 0},
      {"char", 0},
      {"const", 0},
      {"continue", 0},
      {"default", 0},
      {"unsigned", 0},
      {"void", 0},
      {"volatile", 0},
      {"while", 0}
    };

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Naaa... the pointers all go to string literals which have global scope and don't move around very much.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    The only sense in which it is "bad" is that it is missing a const.
    No, there is no memory allocation going on there, nor should there be. The pointers are made to point to something that exists permanently for the lifetime of the program.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt while defining array and pointer
    By karthik537 in forum C Programming
    Replies: 4
    Last Post: 08-24-2010, 12:05 AM
  2. pointer doubt....
    By roaan in forum C Programming
    Replies: 14
    Last Post: 07-29-2009, 11:20 AM
  3. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  4. Doubt regarding pointer
    By karthik537 in forum C Programming
    Replies: 7
    Last Post: 01-21-2009, 08:53 AM
  5. A doubt regarding FILE * pointer
    By rohan_ak1 in forum C Programming
    Replies: 4
    Last Post: 08-01-2008, 05:15 AM

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