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?

http://c-faq.com/ansi/undef.html

To answer the first question with the second question, an example of implementation defined behaviour is >> on negative numbers.

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.

Last public draft of C99
Just scroll down to annex J, and they're all listed there.
C89 will have a few less, C++ will have a lot more.

commented: Thanks Salem +3

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

Thank you both for the help gentlemen :!:

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:

commented: Thanks for doing my cleanup. -- Dave +9

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. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.