473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

More amusing C grammer


The following code also shows some amusing C grammar features:

/* typedef unsigned int uint_t ... */
int typedef unsigned uint_t;

/* defaults to int type in typedef... */
typedef int_t;

main()
{
uint_t x ;
int_t i ;
}

Nov 15 '05 #1
5 1519
Colin King wrote:
The following code also shows some amusing C grammar features:

/* typedef unsigned int uint_t ... */
int typedef unsigned uint_t;
This is just changing the order of the qualifiers, which is quite
acceptable. It's just like how there's no difference between `const char
*' and `char const *'.
/* defaults to int type in typedef... */
typedef int_t;


As far as I know, this is an example of implicit int, which was removed
in C99. The code is no longer valid C.

--
Simon.
Nov 15 '05 #2
Simon Biber wrote:
Colin King wrote:
The following code also shows some amusing C grammar features:

/* typedef unsigned int uint_t ... */
int typedef unsigned uint_t;

This is just changing the order of the qualifiers, which is quite
acceptable. It's just like how there's no difference between `const char
*' and `char const *'.

Errr... what? 'typedef' is a qualifier now?

It's one thing to say 'typedef int unsigned uint_t' is just the same.
'int typedef unsigned uint_t' is another matter. If the C grammar really
considers typedef to be in the same category as 'const'... it's weird.

Not that weirdness is weird, when it comes to C.

S.
Nov 15 '05 #3
Skarmander wrote:
Simon Biber wrote:
Colin King wrote:
The following code also shows some amusing C grammar features:

/* typedef unsigned int uint_t ... */
int typedef unsigned uint_t;
This is just changing the order of the qualifiers, which is quite
acceptable. It's just like how there's no difference between `const
char *' and `char const *'.

Errr... what? 'typedef' is a qualifier now?


No, actually. To be more accurate, according to the C grammar, `typedef'
is a storage-class specifier. As part of a declaration, storage-class
specifiers can be mixed in any order with type specifiers, type
qualifiers, or the function specifier `inline'. See C99 6.7 and 6.7.1.
It's one thing to say 'typedef int unsigned uint_t' is just the same.
'int typedef unsigned uint_t' is another matter. If the C grammar really
considers typedef to be in the same category as 'const'... it's weird.

Not that weirdness is weird, when it comes to C.


Yes, C grammar is weird.

--
Simon.
Nov 15 '05 #4
Simon Biber wrote:
Skarmander wrote:
Simon Biber wrote:
Colin King wrote:

The following code also shows some amusing C grammar features:

/* typedef unsigned int uint_t ... */
int typedef unsigned uint_t;


This is just changing the order of the qualifiers, which is quite
acceptable. It's just like how there's no difference between `const
char *' and `char const *'.

Errr... what? 'typedef' is a qualifier now?

No, actually. To be more accurate, according to the C grammar, `typedef'
is a storage-class specifier. As part of a declaration, storage-class
specifiers can be mixed in any order with type specifiers, type
qualifiers, or the function specifier `inline'. See C99 6.7 and 6.7.1.

Completely bizarre, yet making sense in some perverse way. That would
mean that in 'typedef const volatile unsigned long int cvulong_t', the
first six words can appear in any order, right?

S.
Nov 15 '05 #5
On Tue, 11 Oct 2005 02:13:49 +0200, Skarmander
<in*****@dontmailme.com> wrote:
<snip>
Completely bizarre, yet making sense in some perverse way. That would
mean that in 'typedef const volatile unsigned long int cvulong_t', the
first six words can appear in any order, right?

Yes. Placing the sc-spec (in this case typedef) anyplace other than
first is officially 'obsolescent' (aka deprecated) since C90, but was
not removed in C99. What may happen in C>=0x is unknown.

There are reasonable arguments for placing the qualifiers before type
and also reasonable arguments for placing them after, so I expect the
Standard will forever allow both. I suppose it might (be changed to)
allow only before or after but not mixed, but that probably doesn't
benefit implementors and arguably doesn't help users very much.
Moreover it 'feels' inconsistent with the feature that you can have
qualifiers in a typedef type already or add them where it is used.

Similarly there are reasonable arguments for different orders among
the qualifiers, and among the type-specs (signed long vs long singed).

- David.Thompson1 at worldnet.att.net
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
12
by: Bob Nelson | last post by:
The November 2003 edition of the ``C/C++ Users Journal'' contains a multi-paged advertising section for Microsoft's Visual C++. NET 2003 product. One section focuses on the compiler as being one...
0
by: Active8 | last post by:
This is amusing. I've got 2 windowing functions for Hamming and Hanning windows I was rewriting and I got ham and han as variables mixed up. vector<MCComplex> vOut = vIn; double han = 0.5 -...
25
by: Peter | last post by:
Hi: I am bored and was wondering: Is it a html page? or
51
by: moosdau | last post by:
my code: do { printf("please input the dividend and the divisor.\n"); if(!scanf("%d%d",&dend,&dor)) { temp1=1; fflush(stdin); } else
0
by: Gridlock | last post by:
I just started to use this, and am trying to figure out how to set up a generic string parameter in the grammer file. There are many grammer items like integer and others, but I can't find a...
29
by: Ark | last post by:
A function int foo(struct T *x) { return (x+1)-x; } should always return a 1, no matter how T is defined. (And int could be replaced with ptrdiff_t for you pedants.) For one thing, it was...
0
by: RamyaKarthik | last post by:
can any one guide me how to write programmer for grammer checke using c/c++
151
by: istillshine | last post by:
There are many languages around: C++, JAVA, PASCAL, and so on. I tried to learn C++ and JAVA, but ended up criticizing them. Is it because C was my first programming language? I like C...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.