Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   some well known stupidness in c99 (http://www.velocityreviews.com/forums/t954594-some-well-known-stupidness-in-c99.html)

fir 11-18-2012 09:21 AM

some well known stupidness in c99
 
It is sad to say so but there is some real
and terrible stupidnes in c99. When i wrote
programs in c (and I am involved c user) I
just use const int for array boundaries but
in c99 (and some previous too, terribly) it
will not compile (see for example
http://stackoverflow.com/questions/1...-at-file-scope ) It is terribly wrong
thing for ppl who just wants to use const int to this
purposes and not to use preprocesor - as I do.
It is terribly stupidness in my opinion, it have to
be changed.


Thomas Richter 11-18-2012 09:41 AM

Re: some well known stupidness in c99
 
Am 18.11.2012 10:21, schrieb fir:
> It is sad to say so but there is some real
> and terrible stupidnes in c99. When i wrote
> programs in c (and I am involved c user) I
> just use const int for array boundaries but
> in c99 (and some previous too, terribly) it
> will not compile (see for example
> http://stackoverflow.com/questions/1...-at-file-scope ) It is terribly wrong
> thing for ppl who just wants to use const int to this
> purposes and not to use preprocesor - as I do.
> It is terribly stupidness in my opinion, it have to
> be changed.


This is valid C++ code, thus one option would be just to switch to C++.
In C, however, const is probably not quite what you expect it to be.


SG 11-18-2012 09:41 AM

Re: some well known stupidness in c99
 
Am 18.11.2012 10:21, schrieb fir:
> It is sad to say so but there is some real
> and terrible stupidnes in c99. When i wrote
> programs in c (and I am involved c user) I
> just use const int for array boundaries but
> in c99 (and some previous too, terribly) it
> will not compile (see for example
> http://stackoverflow.com/questions/1712592/ ) It is terribly wrong
> thing for ppl who just wants to use const int to this
> purposes and not to use preprocesor - as I do.
> It is terribly stupidness in my opinion, it have to
> be changed.


To my knowledge this has been the way in C for ever. Are you complaining
about C99 not adopting the C++ style in treating a file-scope const
"variable" with a constant initializer as a constant [compile-time]
expression? Or are you suggesting that C90 handles this any better and
that C99 is actually a regression in this department?

In C++ you can actually do this and

const int foo = 10;

is implicitly static (file-scope) due to the top-level constness and foo
can be used as compile-time constant expression. This is by design
because B. Stroustrup doesn't like macros very much, either.

I sort of accepted this difference between C and C++. In C you just have
to #define something like this in order to be able to use it as the size
of a non-VL array. But I would appreciate it if this unnecessary
incompatibility went away...


fir 11-18-2012 10:02 AM

Re: some well known stupidness in c99
 
W dniu niedziela, 18 listopada 2012 10:41:55 UTC+1 użytkownik SG napisał:
> Am 18.11.2012 10:21, schrieb fir:
>
> > It is sad to say so but there is some real

>
> > and terrible stupidnes in c99. When i wrote

>
> > programs in c (and I am involved c user) I

>
> > just use const int for array boundaries but

>
> > in c99 (and some previous too, terribly) it

>
> > will not compile (see for example

>
> > http://stackoverflow.com/questions/1712592/ ) It is terribly wrong

>
> > thing for ppl who just wants to use const int to this

>
> > purposes and not to use preprocesor - as I do.

>
> > It is terribly stupidness in my opinion, it have to

>
> > be changed.

>
>
>
> To my knowledge this has been the way in C for ever. Are you complaining
>
> about C99 not adopting the C++ style in treating a file-scope const
>
> "variable" with a constant initializer as a constant [compile-time]
>
> expression? Or are you suggesting that C90 handles this any better and
>
> that C99 is actually a regression in this department?
>
>
>
> In C++ you can actually do this and
>
>
>
> const int foo = 10;
>
>
>
> is implicitly static (file-scope) due to the top-level constness and foo
>
> can be used as compile-time constant expression. This is by design
>
> because B. Stroustrup doesn't like macros very much, either.
>
>
>
> I sort of accepted this difference between C and C++. In C you just have
>
> to #define something like this in order to be able to use it as the size
>
> of a non-VL array. But I would appreciate it if this unnecessary
>
> incompatibility went away...


yes, i know; i dislike #define and must to switch to c++ compatybility modeto compile
my besides that pure c codes

it is terrible, it should just change becouse
in other way though I am c (not c++) coder I must throw c compilers to trashbin - becouse
I dislike macros and do not use no one of them

c should just accept

const int table_max = 1000;
int table[table_max};

I do not know where this no 'const int array boundaries' dirty **** originates
but it seem to me that in older c there it was possible to use const ints as array boundaries, (not sure to this, usualy switched to c++ mode to resolve other old c troubles with int i before for loop and so :/ )

make c const int usable in c, call the comitee or compiler writers to include some switch :/






SG 11-18-2012 10:23 AM

Re: some well known stupidness in c99
 
Am 18.11.2012 11:02, schrieb fir:
> W dniu niedziela, 18 listopada 2012 10:41:55 UTC+1 użytkownik SG napisał:
>> Am 18.11.2012 10:21, schrieb fir:
>>
>>> It is sad to say so but there is some real
>>> and terrible stupidnes in c99. When i wrote
>>> programs in c (and I am involved c user) I
>>> just use const int for array boundaries but
>>> in c99 (and some previous too, terribly) it
>>> will not compile (see for example
>>> http://stackoverflow.com/questions/1712592/ )


[snip]

>> To my knowledge this has been the way in C for ever.


[snip]

>> of a non-VL array. But I would appreciate it if this unnecessary
>> incompatibility went away...

>
> yes, i know; i dislike #define and must to switch to c++ compatybility mode to compile
> my besides that pure c codes


[snip]

> c should just accept
>
> const int table_max = 1000;
> int table[table_max};
>
> I do not know where this no 'const int array boundaries' dirty **** originates
> but it seem to me that in older c there it was possible to use const ints as array boundaries, (not sure to this, usualy switched to c++ mode to resolve other old c troubles with int i before for loop and so :/ )


I don't think you're right. "older C" wasn't "better" in that respect.

fir 11-18-2012 10:26 AM

Re: some well known stupidness in c99
 
>
>
> I don't think you're right. "older C" wasn't "better" in that respect.


ok :-(

Nick Keighley 11-18-2012 11:47 AM

Re: some well known stupidness in c99
 
On Nov 18, 9:21*am, fir <profesor....@gmail.com> wrote:

> It is sad to say so but there is some real
> and terrible stupidnes in c99. When i wrote
> programs in c (and I am involved c user) I
> just use const int for array boundaries


no you didn't

> but
> in c99 (and some previous too, terribly)


all previous

> it
> will not compile (see for examplehttp://stackoverflow.com/questions/1712592/variably-modified-array-at...*) It is terribly wrong
> thing for ppl who just wants to use const int to this
> purposes and not to use preprocesor - as I do.
> It is terribly stupidness in my opinion, it have to
> be changed.


:-)

C changes pretty slowly so don't hold your breath


Ben Bacarisse 11-18-2012 12:16 PM

Re: some well known stupidness in c99
 
fir <profesor.fir@gmail.com> writes:
<snip>
> I do not know where this no 'const int array boundaries' dirty ****
> originates but it seem to me that in older c there it was possible to
> use const ints as array boundaries, (not sure to this, usualy switched
> to c++ mode to resolve other old c troubles with int i before for loop
> and so :/ )


It seems you've been writing C++ for some years now, so why not just be
a happy C++ programmer rather than an unhappy C one?

--
Ben.

fir 11-18-2012 01:27 PM

Re: some well known stupidness in c99
 
W dniu niedziela, 18 listopada 2012 13:16:48 UTC+1 użytkownik Ben Bacarisse napisał:
> fir <profesor.fir@gmail.com> writes:
>
> <snip>
>
> > I do not know where this no 'const int array boundaries' dirty ****

>
> > originates but it seem to me that in older c there it was possible to

>
> > use const ints as array boundaries, (not sure to this, usualy switched

>
> > to c++ mode to resolve other old c troubles with int i before for loop

>
> > and so :/ )

>
>
>
> It seems you've been writing C++ for some years now, so why not just be
>
> a happy C++ programmer rather than an unhappy C one?
>


becouse i dislike all c++ features (and soul), and deply appreciate most ofc features (and its spirit), this

const int table_max = 100;
int table[table_max];

i consider as it should belong to c language also It should be, it is terrible that it fails here, (indeed i write in c but i change
to c++ becouse of some old c slight quirks
and was unaware that this terrible const int
boundary distaster is present here

Ben Bacarisse 11-18-2012 02:24 PM

Re: some well known stupidness in c99
 
fir <profesor.fir@gmail.com> writes:

You might want to look into using either the older Google groups
interface or a stand-alone news reader. The new Google groups seems to
mess up posts that go to Usenet very badly. (You might also consider
using your shift key.)

> W dniu niedziela, 18 listopada 2012 13:16:48 UTC+1 użytkownik Ben Bacarisse napisał:
>> fir <profesor.fir@gmail.com> writes:
>>
>> <snip>
>>
>> > I do not know where this no 'const int array boundaries' dirty ****

>>
>> > originates but it seem to me that in older c there it was possible to

>>
>> > use const ints as array boundaries, (not sure to this, usualy switched

>>
>> > to c++ mode to resolve other old c troubles with int i before for loop

>>
>> > and so :/ )

>>
>>
>>
>> It seems you've been writing C++ for some years now, so why not just be
>>
>> a happy C++ programmer rather than an unhappy C one?
>>

>
> becouse i dislike all c++ features (and soul), and deply appreciate
> most of c features (and its spirit),


You obviously don't dislike all C++ features since you want C to adopt
one of them!

> this
> const int table_max = 100;
> int table[table_max];


You don't *have* to use a macro. You can use an enum constant instead:

enum { table_max = 100 };
int table[table_max];

> i consider as it should belong to c language also It should be, it is
> terrible that it fails here, (indeed i write in c but i change to c++
> becouse of some old c slight quirks and was unaware that this terrible
> const int boundary distaster is present here


You have only two realistic options: keep using C++, or switch back to C
and use a macro or an enum. There is no hope at all that the C
committee will change the meaning of const any time soon. It's likely
to be 10 years before the next major revision of the language and even
then I don't think it's likely. If you want to try, posting here is
going to be of little use. You'll need a proposal and, probably,
backing from your national standards body.

BTW, I agree with you in theory: C should have used C++'s meaning of
const from the start, but back in the late 80s no one new that C++ would
become what it has, and C compilers were already using the more
restricted notion that became standard.

--
Ben.


All times are GMT. The time now is 08:12 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.