Hello ladies and gents,

Gotta few questions if you don't mind:

1) Exc_6_4) Wrote a table of values for the bitwise logical operators and was wondering if any of you could check them out whether they are correct this way.

2) I have to write five examples of undefined behaviour and five examples of implementation-defined behaviour. I'm I correct in assuming that undefined behaviour happens when you've written code that is although accepted by your compiler, doesn't behave as you intented or even let's your computer crash and that implementation-defined is when you've written code for which your compiler gives you a warning about?

Attachments
// Exercise 6.6.4
// Write a table of values for the bitwise logical operations (6.2.4) for all possible combinations of 0 and 1 operands.

&, |, ^, ~, >>, <<

bitwise AND &:	bitwise OR |:	bitwise exclusive OR ^:

0 & 0 = 0	0 | 0 = 0	0 ^ 0 = 0			
0 & 1 = 0	0 | 1 = 1	0 ^ 1 = 1		
1 & 0 = 0	1 | 0 = 1	1 ^ 0 = 1
1 & 1 = 1	1 | 1 = 1	1 ^ 1 = 0

bitwise complement NOT ~:	bitwise left shift <<:	bitwise right shift >>:
0 ~= 1				0001<<1 = 0010		1000>>1 = 0100
1 ~= 0				0001<<2 = 0100		1000>>2 = 0010
				0001<<3 = 1000		1000>>3 = 0001

Hi Salem,

Thanks for the link, but, to me, it reades rather abstract and doesn't really tell me if what I wrote was correct.

Can you tell me whether the following examples are examples of undefined and implementation-defined constructs:

// Implementation defined:

1) unsigned char c2 = 1256; // implementation defined.
2) char ch = 'j'; char *p = ch; // implementation defined.


// Undefined behaviour:

1) num /= 0; // undefined behaviour.
2) int arr[2] = {0};
for(int i = 0; i < 4; i++) // undefined behaviour.
arr;
3) int arr[2] = {1, 2, 3}; // undefined behaviour.

Nope, can't find it, opened parent directory, searched for anex J, doesn't seem to be in the list.

Hi Dave

I'm not Dave, but hi anyway! :)

You're speaking of the C90 list, but yet, the Draft shown is C89, am I missing something?

C89 and C90 are different documents of the same standard. C89 was ratified by ANSI and C90 was ratified by ISO with slightly different wording here and there. Some people use C89 and C90, or even C95, to mean the same thing. C95 was the first addendum that added things like locales to the C language, so when someone says C89 or C90 they probably mean C95.

Also, what is actually C89, C90, etc... all about, are they like definitions of what C/C++ compiler writers have to keep in consideration?

Yes, that's it exactly. :) The C standard is a document that officially defines what people can expect from the C language. Anyone who writes a compiler and wants it to conform has to follow that standard. There's one de facto standard, one american standard, and three international standards. In order of earliest to most current, those standards are K&R defined by the first C compiler, C89 defined by ANSI, C90 defined by ISO, C95 defined by ISO, and C99 defined by ISO. ISO is the current body in control of the standard.

Which ones to use are pretty easy. Prestandard legacy code uses K&R, just about everyone right now uses C95, and when more compilers support it, people will start using C99 more. New code should be written in either C95 or C99. Okay, maybe that wasn't so easy. :eek:

Comments
Thanks for doing my cleanup. -- Dave

I'm not Dave, but hi anyway! :)

Hi Ravalon :cheesy:

Yes, that's it exactly. :)

Ok, that's what I needed to know.

New code should be written in either C95 or C99. Okay, maybe that wasn't so easy. :eek:

When you speak of "new code", you do mean "new code" written by those compiler developers right? If not, then yeah, you got me confused again :cheesy:

When you speak of "new code", you do mean "new code" written by those compiler developers right? If not, then yeah, you got me confused again :cheesy:

New code means anything you write from scratch as opposed to anything that already exists and needs to be maintained. Compilers should support a recent standard, but that doesn't mean the recent standard is backward compatible with all previous standardds. There are a lot of subtle differences between K&R C and C89, and even C89 code can fail to compile under C99. ;)

This question has already been answered. Start a new discussion instead.