16x16Matrix

P

Peter Nilsson

Henryk wrote:
[> > > char pippo [2] = "AE"; ]
I compiled it as C++. Is there a difference between C and C++ that I am
not aware of?

Obviously.

In C++, the array must be big enough to house the entire string
literal, including the terminating null byte. C makes an explicit
concession that the null byte (alone) may be ignored in such
initialisations.

Consider it a lesson that C is not C++.
 
C

CBFalconer

Henryk said:
.... snip ...
Your strings need 3 bytes because of the terminating '\0'.

are you certain of that?

char pippo [2] = "AE";

.Net dos not compile complaining array bounds overflow.

Filling in exactly 2 chars without the '\0' would need something like

char pippo[2] = {'A', 'E'};

Utter nonsense. Sounds like you are using some sort of
non-standards compliant Microsoft junk. That is always a mistake.

[1] c:\c\junk>cat junk.c
#include <stdio.h>

int main(void) {

char gubris[2] = "AB";
int i;

for (i = 0; i < 2; i++) putchar(gubris);
putchar('\n');
return 0;
}
[1] c:\c\junk>gcc junk.c
[1] c:\c\junk>.\a
AB

The following (from N869, section 6.7.8) covers it:

[#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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
C

CBFalconer

Lew said:
Apparently, yes.

There are differences between C and C++.
You are apparently not aware that there are differences. Thus,
there is at least one difference between C and C++ that you are
not aware of.

I may be wrong, but I don't believe this is one of them. C++
defers to the C standards for the basics. I think this is just
another Microsoft fouling of standards.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
K

Keith Thompson

CBFalconer said:
I may be wrong, but I don't believe this is one of them. C++
defers to the C standards for the basics. I think this is just
another Microsoft fouling of standards.

I'm fairly sure this is a difference between C and C++; both gcc/g++
and Sun's C and C++ compilers think so too.
 
H

Henryk

I'm not using only Microsoft "junk". I'm using gnu and other processor
specific "junk" too. ;o)

As Peter stated, this really seems to be a difference between C and C++
since gcc and g++ show it.

Actually almost all code I write is C++, so I never got this little
difference to plain C. But now I know ... ;o)

Btw, Microsoft complains even if the file suffix is .c and I set the
options for this particular file to "compile as C file".
 
H

Henryk

Ooooops, I was too fast posting...

Microsoft .Net knows this little difference as well!

Just my stupid mistake. Ok I need more coffee to wake up... ;o)
 
C

CBFalconer

Henryk said:
I'm not using only Microsoft "junk". I'm using gnu and other
processor specific "junk" too. ;o) ... snip ...

Your article is meaningless without adequate context. Most people
have a much different view of a thread than do googleniks. They
cannot see older articles, and may in fact have never received
them. So you should always ensure your articles can stand by
themselves. For means of so doing, even on the broken google
interface to usenet, see my sig. below. Especially read the URL
referenced.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
D

Default User

CBFalconer said:
Lew Pitcher wrote:

I may be wrong, but I don't believe this is one of them. C++
defers to the C standards for the basics. I think this is just
another Microsoft fouling of standards.

No. C++ only includes the C standard library implicitly. There are
differences between the languages. This is one them.



Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,484
Latest member
JackRichard

Latest Threads

Top