Null Terminated Arrays

This is a discussion on Null Terminated Arrays within the A Brief History of Cprogramming.com forums, part of the Community Boards category; >>in C++(maybe C now) reading one past the end of an array is legal and guaranteed to work i havn't ...

  1. #16
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    >>in C++(maybe C now) reading one past the end of an array is legal and guaranteed to work


    i havn't got $250 to buy a copy of the standard from http://www.ansi.org, and point it out to ya, and i don't feel like hunting down an illegal copy.

    so, get a C++ book that covers arrays(The C++ Programming Language by Bjarne Stroustrup) or even the STL, and read it, or read THE STL HEADERS!!!! A LOT OF THE STL RELIES ON THIS TO WORK!!!!FOR ONE THE VECTOR CLASS!!!!!!!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  2. #17
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    I have the Stroustrup book. What you say is wrong. You are wrong. So stop yelling and study. It's ok to be wrong. What is not ok is to adamant.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #18
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well let me explain the problem and maybe there a better way to solve it then with /0. If have someone pass my function (it's in a library) a pointer to the start of an array. Now this array could be multidimensional. So I was going to have them give me the number of dimensions, and then a pointer to an array with all the numbers for the dimensions. I was just looking for an easier and more convenient way for the user. Any ideas?

  4. #19
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >so, get a C++ book that covers arrays(The C++ Programming Language by Bjarne Stroustrup) or even the STL, and read it, or read THE STL HEADERS!!!! A LOT OF THE STL RELIES ON THIS TO WORK!!!!FOR ONE THE VECTOR CLASS!!!!!!!<

    It just so happens I've got that book (luckily mine's not all caps, it makes it easier to read you know).

    I believe you are slighly confused. What I think you are refering to are iterators, whereby a sentinel value is used to mark the end. This isn't the same as being allowed to use the contents one passed to end of the array. Even if you use bog standard arrays in the STL algorithms, you will never actually use the address of the element one past the end of the array. It is just used as the address to stop at. For instance if you have an array

    int a[10];

    and then a for loop

    for (i=0;i!=10;++i)
    //do something with a[i]

    10 is used as the location of the element one past the end of the array. It would be used as array.end() in iterator speak, but would never be assigned from/to.

    btw, the draft standard is freely available.

  5. #20
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    Originally posted by Mario
    I have the Stroustrup book. What you say is wrong. You are wrong. So stop yelling and study. It's ok to be wrong. What is not ok is to adamant.
    I can't study, I'm just not patient enough I can maybe read 10 minutes every hour at max!

    Now, does anyone know where I can get sum sweet amphetamine to keep me up for 96 hours, so that I can cram all the **** into my head once and for all?
    Last edited by Zewu; 06-15-2002 at 01:46 PM.

  6. #21
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well that adds up to be exactly half a full work day every day.

  7. #22
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    >I was just looking for an easier and more convenient way for the user. Any ideas?

    unfortunatly no, unless you designate a value(s) for the end the lengths must be supplied.

    >
    I have the Stroustrup book. What you say is wrong. You are wrong. So stop yelling and study. It's ok to be wrong.
    <

    don't preach to me i've been doing this for years... and i still get confused...

    >What is not ok is to adamant.

    you are quite right, but as i exlain in a sec i didn't realize it.

    >btw, the draft standard is freely available.

    where at? i have yet to see one.

    Sorensen, Sean, everybody else...

    im sorry, you are right, i have a tendancy to get confused sometimes especially when im tired and stressed(i try to avoid anything requiring thought), and i get a little overboard... i realized my error about an hour ago and i see that Sorensen has pointed out ONE of them... anyways i feel stupid now!

    thanks a bunch.hehe...

    not to make excuses im under an extraordinary stress lately so im a bit testy, tired, sick, and over stressed. i apologize.

    my blood pressure is way to high for no apparent reason 146 over 82 which is not good at all and i was calm and relaxed when they took it, im very certain it goes much higher... i can feel it when it does.

    i'm way to young to be dealing with the **** im dealing with now, so please don't judge me to harshly.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  8. #23
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Wow... that is high.... I have really low blood pressure. It's usually something 100/60

  9. #24
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    I have worried much about my heart lately

  10. #25
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    My blood pressure used to go sky high from time to time. I did a series of experiments, and discovered the sky high values often occurred after I had eaten, narrowing down, after I had eaten cheese. When I went to my quack with my results, she did some tests and found I was lactose intolerant, i.e. allergic to milk.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #26
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    This makes me think of a really strong magnet, which almost drags your heart out, so that you can see the shape of it, like in a cartoon, and then loses it's magnetism. Then the heart goes back and pumps out the blood in hyper speed, so that all the blood vessels burst at the end, and thus, all the organs burst, and you die.

  12. #27
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    So much for iron being an essential part of your diet....

  13. #28
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I've heard of this too. I belive code such as

    int a[10];
    int*p = a;
    p--;

    Is undefined since p points before the array. But code like

    int a[10]
    int* p = &a[10];

    is correct but to dereferance the pointer is undefined of course.
    This is useful in implementations of the stl since for something
    like

    Code:
    vector<int> a;
    
    for (vector<int>::iterator i = a.begin(); i != a.end(); ++i)
          continue;
    a.end() could return a pointer to the end of the array.

  14. #29
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    > I did a series of experiments, and discovered the sky high values often occurred after I had eaten, narrowing down, after I had eaten cheese.

    cheese huh? man that sucks... no milk.

    i live on cheese...

    >a.end() could return a pointer to the end of the array.

    yes, this is what i was thinking of... using the adress is legal but not accessing, i'm not doin well of late.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  15. #30
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Yeah - but that would actually call for mor arguments. I'll think of something...

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

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  3. Big Problem With Passing an Matrix to Main Function
    By Maragato in forum C Programming
    Replies: 4
    Last Post: 06-14-2004, 11:06 PM
  4. Really Need Help With My Opengl Camera!!!!
    By psychopath in forum Game Programming
    Replies: 13
    Last Post: 05-28-2004, 03:05 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM

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