![]() |
| | #31 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 656
|
__________________ HOPE YOU UNDERSTAND....... for( ; ; ) printf("If you can't make it good, at least make it look good"); PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition Last edited by BEN10; 04-30-2009 at 10:07 PM. |
| BEN10 is offline | |
| | #32 | |
| Registered User Join Date: Apr 2009 Location: Russia
Posts: 116
| Quote:
I never thought that in arr[N] array N+1 elements, it was seemed to strickyc | |
| c.user is offline | |
| | #33 | |
| Registered User Join Date: Apr 2009
Posts: 41
| Quote:
char a[5] = "ABCDE"; is correct coding. And I'm pretty sure K&R point out that this is incorrect. C by example also says this is wrong. C how to program by Deitel & Deitel also point it out as wrong. I'm sure every book with a beginners chapter on character arrays points this out as wrong. Last edited by strickyc; 05-01-2009 at 07:57 PM. | |
| strickyc is offline | |
| | #34 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| I've already pointed out that it's legal in C, when initializing character arrays at the time of declaration. For any other variable type it's not. But they allow it for character arrays in C. Not in C++, but C allows it. In my opinion, it shouldn't be legal; but it is allowed. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #35 | |
| Registered User Join Date: Apr 2009
Posts: 41
| Quote:
| |
| strickyc is offline | |
| | #36 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| It's both. It's a logic error, but were it any other data type, and you were providing more initializers than elements, it would be a programming error. There's no reason it should be allowed, other than for the sake of "because we wanted it to". And no one gives a ........ if you want to learn C++ or not. I was illustrating the point that while I feel it should be an error in C, the authors of C++ apparently decided it was wrong as well, since they've changed the legality of it. Providing more initializers than element space should always generate an error. There shouldn't be one specific case where it isn't an error. I know why they did it; because they wanted an easy way to fill character arrays, without having to initialize them by hand. But you can't do it for any other data type, so you shouldn't be able to do it for this one. Your "in come cases you don't really need..." statement is irrelevant. In the event you don't need a null character, you should be forced to initialize each element one at a time, the same as any other array. It's a poor idea, and it's one of the reasons people get confused about the boundries of arrays. "Well how come I can do it here?" "Oh, just because. There's no logical reason for it. This is an exception for JUST this data type." "That's dumb." "Yeah well that's how it goes." Furthermore, since half the new people that show up here are compiling on a C++ compiler anyway, we end up answering the question "But why does it generate an error for me if it's allowed?" anyway. So regardless if YOU want to learn C++ or not, you'll need to understand that I'm not here just for YOU. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #37 | |||||||
| Registered User Join Date: Apr 2009
Posts: 41
| Quote:
Quote:
C++ you have a boolean in C you tehnicaly don't. If you have the need of several Bools in c you can just use one char bits. C++ isn't C, but they do influence each other. What would be the use of two programming languages that do exactly the same thing? Quote:
but his code even though a logical error isn't wrong cause the array has room for what hes trying to do. They are just more uses for a char than storing letters and symbols this is why they did it. Quote:
takes some time to remeber that and array of 20 elements end on the 19th one. and with initialized character arrays the null terminating character is added automatically Quote:
Quote:
Quote:
Suck my ass. Last edited by strickyc; 05-01-2009 at 09:12 PM. | |||||||
| strickyc is offline | |
| | #38 | |||
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Quote:
Quote:
Quote:
It's nice of you to come here and give us a lesson on the differences between C and C++ though. | |||
| bithub is offline | |
| | #39 | ||||
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| Quote:
Code: unsigned char bitfield[ SOMESIZE ] =
{
FLAG_X | FLAG_Y,
FLAG_Z | FLAG_C | FLAG_G ,
...
};
Quote:
I'm not even sure what you're arguing here any more. We both agreed that he was using an incomplete string, and that his initialization was fine. We also both agreed that using string.h was fine, so long as he pays attention to the length allocated for his incomplete array. What you seem to have been confused on, was if this was legal or not: Code: char array[ 5 ] = "12345"; Quote:
Quote:
To quote Rhett Butler, "Frankly, my dear, I don't give a damn." Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | ||||
| quzah is offline | |
| | #40 | ||
| Registered User Join Date: May 2009
Posts: 1
| Quote:
Quote:
Code: #include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
char a1[5] = "ABCDE";
return 0;
}
Code: 'a1' : array bounds overflow (And also because I thought it should throw an error too.)It is offensive, but then it's also childish. Why you'd want people to have to continuously read your filth is beyond me. It probably drives people away - or is that your intent? | ||
| smelt is offline | |
| | #41 |
| Registered User Join Date: Apr 2009 Location: Russia
Posts: 116
| Code: C99
6.7.8
[#14] An array of character type may be initialized by a
character string literal, optionally enclosed in braces.
Successive characters of the character string literal
(including the terminating null character if there is room
or if the array is of unknown size) initialize the elements
of the array.
|
| c.user is offline | |
| | #42 | ||
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| Quote:
Quote:
Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | ||
| quzah is offline | |
![]() |
| Tags |
| string |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with comparing strings (I'm a beginner C programmer) | Bandizzle | C Programming | 2 | 04-29-2009 10:13 AM |
| beginner question about strings | gp364481 | C Programming | 4 | 09-05-2008 06:31 PM |
| beginner: dynamic array of strings | pc2-brazil | C++ Programming | 10 | 04-29-2008 04:29 PM |
| Strings Program | limergal | C++ Programming | 4 | 12-02-2006 03:24 PM |
| A beginner passing strings | jamjar | C Programming | 2 | 09-01-2002 12:50 AM |