+1  A: 

Because C is Standardized. Compiler could offer that feature and some do, but using it means that the source code doesn't follow the standard and could only be compiled on that vendor's compiler.

James Curran
+2  A: 

As already mentioned, C has a standard that needs to be adhered to. But can't you just write your code using slightly modified C syntax, but use a C++ compiler so that things like

struct elem
{
 int i;
 char k;
};
elem user;

will compile?

Bill the Lizard
ya.from ur answer only i got that basic doubt.bcos iam "Manoj doubts"but why dont we make the C compiler more user friendly?
Manoj Doubts
Well, in a way we did, we came up with C++ (and by "we", I mean Bjarne Stoustroup). Remember you can compile all of your C code using C++, and ignore all of the parts of C++ that you don't like.
Bill the Lizard
+2  A: 

We have a typedef for exactly this purpose. And please do not change the standard we have enough compatibility problems already....

@ Manoj Doubts comment
I have no problem with you or somebody else to define C+ or C- or Cwhatever unless you don't touch C :)
I still need a language that capable to complete my task - have a same piece of code (not a small one) to be able to run on tens of Operating system compiled by significant number of different compilers and be able to run on tens of different hardware platform at the moment there is only one language that allow me complete my task and i prefer not to experiment with this ability :) Especially for reason you provided. Do you really think that ability to write

foo test;

instead

struct foo test;

will make you code better from any point of view ?

Ilya
why dont we remove them and get a new one called C+ (in between C, C++)
Manoj Doubts
Because C+ wouldn't compile... C and C++ will. We'd have to go with something like C+.5*C - doesn't have that nice of a ring to it
Knobloch
+10  A: 

Because it takes years for a new Standard to evolve. They are working on a new C++ Standard (C++0x), and also on a new C standard (C1x), but if you remember that it usually takes between 5 and 10 years for each iteration, i don't expect to see it before 2010 or so.

Also, just like in any democracy, there are compromises in a Standard. You got the hardliners who say "If you want all that fancy syntactic sugar, go for a toy language like Java or C# that takes you by the hand and even buys you a lollipop", whereas others say "The language needs to be easier and less error-prone to survive in these days or rapidly reducing development cycles".

Both sides are partially right, so standardization is a very long battle that takes years and will lead to many compromises. That applies to everything where multiple big parties are involved, it's not just limited to C/C++.

Michael Stum
+13  A: 
typedef struct
{
 int i;
 char k;
} elem;

elem user;

will work nicely. as other said, it's about standard -- when you implement this in VS2008, you can't use it in GCC and when you implement this even in GCC, you certainly not compile in something else. Method above will work everywhere.

On the other side -- when we have C99 standard with bool type, declarations in a for() cycle and in the middle of blocks -- why not this feature as well?

Miro Kropacek
Indeed, I feel you make the most interesting point. If c99 c-code won't compile on pre-c99 compilers, then why not add this feature and allow us to remove unnecessary tokens from our codebases.
Max Howell
+1  A: 

Well,

1 - None of the compilers that are in use today are from the 70s...

2 - There are standarts for both C and C++ languages and compilers are developed according to those standarts. They can't just change some behaviour !

3 - What happens if you develop on VS2008 and then try to compile that code by another compiler whose last version was released 10 years ago ?

4 - What happens when you play with the options on the C/C++ / Language tab ?

5 - Why don't Microsoft compilers target all the possible processors ? They only target x86, x86_64 and Itanium, that's all...

6 - Believe me , this is not even considered as a problem !!!

Malkocoglu
+6  A: 

Most people still using C use it because they're either:

  • Targeting a very specific platform (ie, embedded) and therefore must use the compiler provided by that platform vendor
  • Concerned about portability, in which case a non-standard compiler would defeat the purpose
  • Very comfortable with plain C and see no reason to change, in which case they just don't want to.
Joel Coehoorn
A: 

You don't need to develop a new language if you want to use C with C++ typedefs and the like (but without classes, templates etc).

Just write your C-like code and use the C++ compiler.

therefromhere
+8  A: 

First and foremost, compilers need to support the standard. That's true even if the standard seems awkward in hindsight. Second, compiler vendors do add extensions. For example, many compilers support this:

(char *) p += 100;

to move a pointer by 100 bytes instead of 100 of whatever type p is a pointer to. Strictly speaking that's non-standard because the cast removes the lvalue-ness of p.

The problem with non-standard extensions is that you can't count on them. That's a big problem if you ever want to switch compilers, make your code portable, or use third-party tools.

C is largely a victim of its own success. One of the main reasons to use C is portability. There are C compilers for virtually every hardware platform and OS in existence. If you want to be able to run your code anywhere you write it in C. This creates enormous inertia. It's almost impossible to change anything without sacrificing one of the best things about using the language in the first place.

The result for software developers is that you may need to write to the lowest common denominator, typically ANSI C (C89). For example: Parrot, the virtual machine that will run the next version of Perl, is being written in ANSI C. Perl6 will have an enormously powerful and expressive syntax with some mind-bending concepts baked right into the language. The implementation, though, is being built using a language that is almost the complete opposite. The reason is that this will make it possible for perl to run anywhere: PCs, Macs, Windows, Linux, Unix, VAX, BSD...

Michael Carman
+2  A: 

Actually, many C compilers do add features - doesn't pretty much every C compiler support C++ style // comments?

Most of the features added to updates of the C standard (C99 being the most recent) come from extensions that 'caught on'.

For example, even though the compiler I'm using right now on an embedded platform does not claim to conform to the C99 standard (and it is missing quite a bit from it), it does add the following extensions (all of which are borrowed from C++ or C99) to it's 'C90' support:

  • declarations mixed with statements
  • anonymous structs and unions
  • inline
  • declaration in the for loop initialization expression
  • and, of course, C++ style // comments

The problem I run into with this is that when I try to compile those files using MSVC (either for testing or because the code is useful on more than just the embedded platform), it'll choke on most of them (I'm honestly not sure about anonymous structs/unions).

So, extensions do get added to C compilers, it's just that they're done at different rates and in different ways (so code using them becomes more difficult to port) and the process of moving them into a standard occurs at a near glacial pace.

Michael Burr
A: 

As several people have mentioned, it would break the C standard. You say, by comparison:

Look at visual studio etc.. It is frequently updated with new releases and for every new release we have to learn some new function usage

But ultimately isn't the non-compatibility more trouble than having to type the word "struct"?

Bruce Alderman
A: 

As far as new functionality in new releases go, Visual C++ is not completely standard-conforming (see http://msdn.microsoft.com/en-us/library/x84h5b78.aspx), By the time Visual Studio 2010 is out, the next C++ standard will likely have been approved, giving the VC++ team more functionality to change.

There are also changes to the Microsoft libraries (which have little or nothing to do with the standard), and to what the compiler puts out (C++/CLI). There's plenty of room for changes without trying to deviate from the standard.

Nor do you need anything like C+. Just write in C, use whatever C++ features you like, and compile as C++. One of the Bjarne Stroustrup's original design goals for C++ was to make it unnecessary to write anything in C. It should compile perfectly efficiently provided you limit the C++ features you use (and even then will compile very efficiently; modern C++ compilers do a very good job).

And the unanswered question: Why would you want to use non-standard C, when you could write standard C or standard C++ with almost equal facility?

David Thornley
A: 

This sounds like the embrace and extend concept. Life under your scenario.

  1. I develop code using a C compiler that has the C "glitches" removed.
  2. I move to a different platform with another C compiler that has the C "glitches" removed, but in a slightly different way.
  3. My code doesn't compile or runs differently on the new platform, I waste time "porting" my code to the new platform.

Some vendors actually like to fix "glitches" because this tends to lock people into a single platform.

David Nehme
+4  A: 

This "feature" will never be adopted by future C standards for one reason only: it would badly break backward compatibility. In C, struct tags have separate namespaces to normal identifiers, and this may or may not be considered a feature. Thus, this fragment:

struct elem
{
    int foo;
};

int elem;

Is perfectly fine in C, because these two elems are in separate namespaces. If a future standard allowed you to declare a struct elem without a struct qualifier or appropriate typedef, the above program would fail because elem is being used as an identifier for an int.

An example where a future C standard does in fact break backward compatibiity is when C99 disallowed a function without an explicit return type, ie:

foo(void); /* declare a function foo that takes no parameters and returns an int */

This is illegal in C99. However, it is trivial to make this C99 compliant just by adding an int return type. It is not so trivial to "fix" C programs if suddenly struct tags didn't have a separate namespace.

Chris Young
Thanks for the answer. As a C++ developer, this exact "problem" in C had bugged me for years. Now that I understand the cause, I understand why it is still there. +1.
paercebal
That is completely legal in C++, in which class object declarations require neither class qualifier nor typedef. so [ elem var; int elem;] or [int elem; ::elem var;] are fine.
Comptrol
+2  A: 

The following program outputs "1" when compiled as standard C or something else, probably 2, when compiled as C++ or your suggested syntax. That's why the C language can't make this change, it would give new meaning to existing code. And that's bad!

#include <stdio.h>

typedef struct
{
    int a;
    int b;
} X;

int main(void)
{
    union X
    {
     int a;
     int b;
    };

    X x;
    x.a = 1;
    x.b = 2;

    printf("%d\n", x.a);

    return 0;
}
A: 

If you want to write in standard C, follow the standards. That's it.

If you want more freedom use C# or C++.NET or anything else your hardware supports.

+5  A: 

I've found that when I've implemented non-standard extensions to C and C++, even when people request them, they do not get used. The C and C++ world definitely revolves around strict standard compliance. Many of these extensions and improvements have found fertile ground in the D programming language.

Walter Bright, Digital Mars

Walter Bright