Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > some well known stupidness in c99

Reply
Thread Tools

some well known stupidness in c99

 
 
Eric Sosman
Guest
Posts: n/a
 
      11-21-2012
On 11/20/2012 7:00 PM, fir wrote:
> [...]
> For example as to
>
> char* main(char* arg)
> {
> return "hallo world";
> }
>
> (or close to that couse there can be unresolved details here)
>
> some people just said that no oses are
> ready for that - but it is not important
> here becousa I am talking about 'technical goodness' here


To me, "technical goodness" has "it works" as a prerequisite.
If it doesn't work, it can't be technically good. I'm just not
interested in elegant failures.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-21-2012
On 11/21/2012 1:30 PM, glen herrmannsfeldt wrote:
> [...]
> Well, new functionality, including labels that aren't resolved at
> compile time and that don't have to be distinct should probably come
> with a new and differently named statement.
>
> How about select/case that takes the first among the choices, and where
> values can be determined at run time?


Like if/else if/else if/.../else?

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
BartC
Guest
Posts: n/a
 
      11-21-2012
"Eric Sosman" <(E-Mail Removed)> wrote in message
news:k8j7qq$f75$(E-Mail Removed)...
> On 11/21/2012 1:30 PM, glen herrmannsfeldt wrote:
>> [...]
>> Well, new functionality, including labels that aren't resolved at
>> compile time and that don't have to be distinct should probably come
>> with a new and differently named statement.
>>
>> How about select/case that takes the first among the choices, and where
>> values can be determined at run time?

>
> Like if/else if/else if/.../else?


Yes. Except it's written as:

switch(x) { case a: ... case b: ... case c: ... default: ...}

(with perhaps a new keyword as suggested) instead of:

if (x==a) ... else if (x==b) ... else if (x==c) ... else ...

with the same advantages that a, b, etc can be run-time expressions of any
type, but without the disadvantage that x is can be evaluated more then
once).

--
Bartc

 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      11-21-2012
W dniu środa, 21 listopada 2012 01:00:37 UTC+1 użytkownik fir napisał:
>
> char* main(char* arg)
> {
> return "hallo world";
> }


I could also add (as to this all) that sometimes
some difficulties make me really sad, for example this above looks really god for me, but
this (when this syntax passes also sizes in the background)

char[] main(char[] arg)
{
return "hallo world";
}

looks worse, maybe something like

char *$ main(char *$ arg)
{
return "hallo world";
}

where *$ means 'adress and size pair' would be better? maybe $a instead of lengthof(a) would be better - it is difficult not to fail aesteheticaly here and it is sad - takes whole years to clarify
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      11-21-2012
Eric Sosman <(E-Mail Removed)> wrote:
> On 11/21/2012 1:30 PM, glen herrmannsfeldt wrote:


>> Well, new functionality, including labels that aren't resolved at
>> compile time and that don't have to be distinct should probably come
>> with a new and differently named statement.

>
>> How about select/case that takes the first among the choices, and where
>> values can be determined at run time?


> Like if/else if/else if/.../else?


Yes, but in a more structured form.

As Fortran I showed, you can do everything with IF and GOTO, but it
is much nicer to program with more structured languages.

Why not a structured form, like switch, for the case where the choices
aren't known until run time? Much more readable than the if/else if/else
series. (Most likely the generated code is in if/else form.)

-- glen
 
Reply With Quote
 
BartC
Guest
Posts: n/a
 
      11-21-2012



"glen herrmannsfeldt" <(E-Mail Removed)> wrote in message
news:k8jd52$15q$(E-Mail Removed)...
> Eric Sosman <(E-Mail Removed)> wrote:
>> On 11/21/2012 1:30 PM, glen herrmannsfeldt wrote:

>
>>> Well, new functionality, including labels that aren't resolved at
>>> compile time and that don't have to be distinct should probably come
>>> with a new and differently named statement.

>>
>>> How about select/case that takes the first among the choices, and where
>>> values can be determined at run time?

>
>> Like if/else if/else if/.../else?

>
> Yes, but in a more structured form.
>
> As Fortran I showed, you can do everything with IF and GOTO, but it
> is much nicer to program with more structured languages.
>
> Why not a structured form, like switch, for the case where the choices
> aren't known until run time? Much more readable than the if/else if/else
> series. (Most likely the generated code is in if/else form.)


Does any recent Fortran (or any language for that matter) actually have such
a statement?

(BTW we are in 2012 now you know, with all this talk of Fortran I and OS
360. I think they were already obsolete when I started programming 35 years
ago...)

In my own language projects, obviously I will have these two kinds of
statements, plus various variations I won't bore you with.

But I have found that people don't seem like useful extra syntax in their
favourite languages. Or perhaps more accurately, if their favourite language
doesn't have a particularly handy construction, they will defend the lack
of it to the death!

So, we don't need an if-else version of switch, because we can just use
if-else, and the compiler will end up generating the same code anyway. But
like you say, there would never be a reason to progress beyond if-then-goto
in that case.

--
Bartc

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      11-21-2012
On 11/22/12 10:42, Lowell Gilbert wrote:
> fir<(E-Mail Removed)> writes:
>>
>> I could also add (as to this all) that sometimes some difficulties
>> make me really sad, for example this above looks really god for me,
>> but this (when this syntax passes also sizes in the background)
>>
>> char[] main(char[] arg) { return "hallo world"; }
>>
>> looks worse, maybe something like
>>
>> char *$ main(char *$ arg) { return "hallo world"; }
>>
>> where *$ means 'adress and size pair' would be better? maybe $a
>> instead of lengthof(a) would be better - it is difficult not to
>> fail aesteheticaly here and it is sad - takes whole years to
>> clarify

>
> I wish I could aspire to this level of comedy.


Aspire away, achievement may be more of a problem!

--
Ian Collins
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      11-21-2012
BartC <(E-Mail Removed)> wrote:

(snip, someone wrote)
>>>> Well, new functionality, including labels that aren't resolved at
>>>> compile time and that don't have to be distinct should probably come
>>>> with a new and differently named statement.


(snip, then I wrote)
>>>> How about select/case that takes the first among the choices, and where
>>>> values can be determined at run time?


>>> Like if/else if/else if/.../else?


>> Yes, but in a more structured form.


>> As Fortran I showed, you can do everything with IF and GOTO, but it
>> is much nicer to program with more structured languages.


>> Why not a structured form, like switch, for the case where the choices
>> aren't known until run time? Much more readable than the if/else if/else
>> series. (Most likely the generated code is in if/else form.)


> Does any recent Fortran (or any language for that matter) actually have such
> a statement?


Verilog has the run-time value switch/case:

http://eesun.free.fr/DOC/VERILOG/ver...nual1.html#7.2

Otherwise, Fortran, I believe since Fortran 90, has SELECT/CASE with
the usual compile-time constants and unique CASE values. (Fortran
CASE allows for a start:end range in addition to single values,
with either start or end, but not both at the same time, optional.)

> (BTW we are in 2012 now you know, with all this talk of Fortran I and OS
> 360. I think they were already obsolete when I started programming 35 years
> ago...)


Sorry about that.

> In my own language projects, obviously I will have these two kinds of
> statements, plus various variations I won't bore you with.


> But I have found that people don't seem like useful extra syntax in their
> favourite languages. Or perhaps more accurately, if their favourite language
> doesn't have a particularly handy construction, they will defend the lack
> of it to the death!


It does take time to get used to change. In the days before Fortran 77
there were various preprocessors to generate standard Fortran from a
new, structured language. RATFOR and MORTRAN are two that I know about.

But they never got as popular as you might think, give the advantages
of structured programming.

> So, we don't need an if-else version of switch, because we can just use
> if-else, and the compiler will end up generating the same code anyway.
> But like you say, there would never be a reason to progress
> beyond if-then-goto in that case.


If it isn't needed all that often, maybe it isn't worth adding.

There is cost in the complexity of compilers, and the ability of people
to remember how to use new features. But people can always use just
their favorite subset when writing their own programs. You have to at
least have a good reference when reading programs written by others.

If I didn't have one, and had a program that needed it, I might write
a special use preprocessor to generate the if/elseif/else chain.

Another possibity is to code the logic to convert the values, possibly
through a loop and look-up table, to constants. Slower, but it might
work well enough.

-- glen
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      11-21-2012
W dniu środa, 21 listopada 2012 22:49:25 UTC+1 użytkownik Ian Collins napisał:
> On 11/22/12 10:42, Lowell Gilbert wrote:
>
> > fir<(E-Mail Removed)> writes:

>
> >>

>
> >> I could also add (as to this all) that sometimes some difficulties

>
> >> make me really sad, for example this above looks really god for me,

>
> >> but this (when this syntax passes also sizes in the background)

>
> >>

>
> >> char[] main(char[] arg) { return "hallo world"; }

>
> >>

>
> >> looks worse, maybe something like

>
> >>

>
> >> char *$ main(char *$ arg) { return "hallo world"; }

>
> >>

>
> >> where *$ means 'adress and size pair' would be better? maybe $a

>
> >> instead of lengthof(a) would be better - it is difficult not to

>
> >> fail aesteheticaly here and it is sad - takes whole years to

>
> >> clarify

>
> >

>
> > I wish I could aspire to this level of comedy.

>
>
>
> Aspire away, achievement may be more of a problem!
>
>


ależ błyskotliwe! (ziew po polsku)
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-21-2012
"BartC" <(E-Mail Removed)> writes:

> "glen herrmannsfeldt" <(E-Mail Removed)> wrote in message
> news:k8jd52$15q$(E-Mail Removed)...
>> Eric Sosman <(E-Mail Removed)> wrote:
>>> On 11/21/2012 1:30 PM, glen herrmannsfeldt wrote:

>>
>>>> Well, new functionality, including labels that aren't resolved at
>>>> compile time and that don't have to be distinct should probably come
>>>> with a new and differently named statement.
>>>
>>>> How about select/case that takes the first among the choices, and where
>>>> values can be determined at run time?

>>
>>> Like if/else if/else if/.../else?

>>
>> Yes, but in a more structured form.
>>
>> As Fortran I showed, you can do everything with IF and GOTO, but it
>> is much nicer to program with more structured languages.
>>
>> Why not a structured form, like switch, for the case where the choices
>> aren't known until run time? Much more readable than the if/else if/else
>> series. (Most likely the generated code is in if/else form.)

>
> Does any recent Fortran (or any language for that matter) actually have such
> a statement?


Perl has a wonderful construct that looks like the proposed case
statement but can't quite be described in these terms. An example:

given ($x) {
$y = 'a' when $a;
$y = 'b' when $b;
$y = 'c' when $c;
}

The reason it's not exactly as described is that the "given" part and
the "when" parts are not connected syntactically. You can, for example,
have a set of "when" clauses in a "while" or "for" loop, and you don't
have to have any inside a "given" statement.

It's an extraordinarily powerful construct, mainly due to the magic
that a "when" clause can do.

Also, I remember an old variant of Algol called Algol-S had exactly
what's been proposed. I've not used it since 1978.

> (BTW we are in 2012 now you know, with all this talk of Fortran I and OS
> 360. I think they were already obsolete when I started programming 35 years
> ago...)


35 years ago system 360 was current. It's what I learnt to program on,
though the systems people hankered after a newer and faster 370...

<snip>
--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is this phase-accumulator trick well-known??? Mike Treseler VHDL 0 02-08-2009 07:17 PM
List mutation method gotcha - How well known? Hendrik van Rooyen Python 20 03-16-2008 09:55 AM
Difference between "library parts" of C99 and "language parts" of C99 albert.neu@gmail.com C Programming 3 03-31-2007 08:14 PM
C99 struct initialization (C99/gcc) jilerner@yahoo.com C Programming 3 02-20-2006 04:41 AM
well-known Internet sites which use Java based web servers Mladen Adamovic Java 3 10-24-2005 09:48 PM



Advertisments