473,671 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1532
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*****@dontma ilme.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.ne t
Nov 15 '05 #6

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

Similar topics

303
17597
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
12
1770
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 of the most ISO compliant on any platform. Overall, the ad is rather interesting and has some worthwhile code snippets. - The amusing part is the declaration of ``main'' in an example showing support for function template specialization:
0
1133
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 - 0.5 * cos( factor * i ); vOut.SetReal( ham * vOut.GetReal() );
25
3291
by: Peter | last post by:
Hi: I am bored and was wondering: Is it a html page? or
51
3861
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
1019
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 generic string parameter. Anyone? Thanks much
29
2363
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 amusing to watch how my compiler (the famed IAR EWARM for ARM) jumps through hoops to arrive at this answer.
0
1070
by: RamyaKarthik | last post by:
can any one guide me how to write programmer for grammer checke using c/c++
151
8024
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 because, comparatively, it is small, efficient, and able to handle large and complex tasks. I could not understand why people are using and talking about other programming languages.
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.