Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > GCC is re-implementing in C++ and C discarded

Reply
Thread Tools

GCC is re-implementing in C++ and C discarded

 
 
Tim Rentsch
Guest
Posts: n/a
 
      09-07-2012
Jens Gustedt <(E-Mail Removed)> writes:

> Am 03.09.2012 21:48, schrieb Herbert Rosenau:
>> Am 02.09.2012 00:59, schrieb Jens Gustedt:
>>> Am 31.08.2012 23:40, schrieb http://www.velocityreviews.com/forums/(E-Mail Removed):
>>>> Jens Gustedt <(E-Mail Removed)> wrote:
>>>>>
>>>>> But it says so implicitly. Prototypes are defined semantically
>>>>> (6.2.1p2), not through syntax: a declaration of a function that
>>>>> declares the types of its parameters. "void foo() { }" perfectly fits
>>>>> in here, it is a definition and it specifies the number and type of
>>>>> its parameters, namely none.
>>>>
>>>> It's always been understood that a declaration of a function has to use
>>>> a parameter-type-list to declare the types of its parameters;
>>>
>>> Out of curiosity, why did the term prototype then never make it to a
>>> syntactical definition? Do you agree with me that if we stick together
>>> the current text as it stands we have that
>>>
>>> - "void foo() { }" is a defintion of "foo"
>>> - it is also a declaration
>>> - it declares that "foo" has no parameters

>>
>> No, it declares foo as a function with an unknown nuber of parameters
>> with onkown rypes each.

>
> How do you come to that "no". In 6.7.6.3p14 it says
>
>> An empty list in a function declarator that is part of a definition of
>> that function specifies that the function has no parameters.

>
> so you are making the difference that a function "declarator" here
> only "specifies" that the function has no parameters but the
> declarator doesn't "declare" that it has no parameters?


This is a settled question: asked in a Defect Report, and the
response is that this case does not provide a prototype. That
might not be the answer you want, but that's the answer.


> Honestly, I am lost, linguistically.
>
> I think term prototype should have been also defined by syntax,
> perhaps in 6.2.5p20 where function types are introduced or even better
> 6.7.6.3p5 where a simple phrase could be added at the end:


I can't say I agree, but in any case if you want to do something
about it then further comments should be addressed to people
in WG14 (aka "the committee"). Since the question has been
asked and answered through a DR, and no changes have been
made to the text of the Standard, there isn't really anything
people in the newsgroup can do for you.
 
Reply With Quote
 
 
 
 
Johannes Bauer
Guest
Posts: n/a
 
      09-07-2012
On 06.09.2012 13:41, Phil Carmody wrote:

> #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0


Boy we're in for a treat. You're a C++ wizard.

> struct ivtlayout ivt = {
> INIT_IVT(0,0,0,0,0,0,0,0,1234,0)
> };
>
>>
>> I'll leave the C++ solution as an excersise to you. Hopefully you'll see
>> the point now.

>
> That took me 20 seconds. How many hours should I bill you for if you think
> it was hard work?


You should apply for a software patent for your ingenious solution. It's
probably worth millions. Marvellous!

> And if you think that using the preprocessor isn't C++, then what about the
> following?
>
> class ivtlayout {
> int vec7;
> int vec6;
> //...
>
> public:
> ivt(int v0, int v1, int v2, /*...*/, int v8, int v9)
> : vec7(v7), vec6(v6), /*...*/, vec8(v, vec9(v9) {;}
> };
>
> ivtlayout ivt(0,0,0,0,0,0,0,0,1234,0);


That doesn't fulfill the requirements. Please look at the generated code.

> E&OE, I've not programmed C++ to any significant extent for about a decade.


And it shows.

Regards,
Johannes

--
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?

> Zumindest nicht öffentlich!

Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Phil Carmody
Guest
Posts: n/a
 
      09-07-2012
Johannes Bauer <(E-Mail Removed)> writes:
> On 06.09.2012 13:41, Phil Carmody wrote:
>
> > #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0

>
> Boy we're in for a treat. You're a C++ wizard.
>
> > struct ivtlayout ivt = {
> > INIT_IVT(0,0,0,0,0,0,0,0,1234,0)
> > };
> >
> >>
> >> I'll leave the C++ solution as an excersise to you. Hopefully you'll see
> >> the point now.

> >
> > That took me 20 seconds. How many hours should I bill you for if you think
> > it was hard work?

>
> You should apply for a software patent for your ingenious solution. It's
> probably worth millions. Marvellous!


If you're attempting to be patronising, I feel obliged to point out
that it was you who was unable to come up with something and getting
in a flap about how it was impossible in C++. I'm sorry if proving
you wrong hurts your pride.

Phil
--
Regarding TSA regulations:
How are four small bottles of liquid different from one large bottle?
Because four bottles can hold the components of a binary liquid explosive,
whereas one big bottle can't. -- camperdave responding to MacAndrew on /.
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      09-07-2012
Johannes Bauer <(E-Mail Removed)> writes:

> On 06.09.2012 13:41, Phil Carmody wrote:
>
> > #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0

>
> Boy we're in for a treat. You're a C++ wizard.


Only relatively. You've not set the standard particularly high.


#if defined(REVERSE)

/* this goes in one header file */
template <int v0, int v1, int v2, int v3> struct IVT
{
IVT() { ; }
static const int ivt[4];
};
template <int v0, int v1, int v2, int v3> const int IVT<v0,v1,v2,v3>::ivt[4] = { v3, v2, v1, v0, };

#else

/* this goes in a different header file */
template <int v0, int v1, int v2, int v3> struct IVT
{
IVT() { ; }
static const int ivt[4];
};
template <int v0, int v1, int v2, int v3> const int IVT<v0,v1,v2,v3>::ivt[4] = { v0, v1, v2, v3, };

#endif

/* back in your C file */
static const IVT<0,0,1234,0> ivt=0; /* IRQ2 initialised, no matter where it is in the array */

#include <iostream>
int main()
{
std::cout << ivt.ivt[0] << ' ' << ivt.ivt[1] << ' ' << ivt.ivt[2] << ' ' << ivt.ivt[3] << std::endl;
return 0;
}



phil@geespaz:tmp$ g++ crap.c -o crap
phil@geespaz:tmp$ ./crap
0 0 1234 0
phil@geespaz:tmp$ g++ -DREVERSE crap.c -o crap
phil@geespaz:tmp$ ./crap
0 1234 0 0


Objdump confirms there's some .rodata with the appropriate values in the appropriate order.

Phil
--
Regarding TSA regulations:
How are four small bottles of liquid different from one large bottle?
Because four bottles can hold the components of a binary liquid explosive,
whereas one big bottle can't. -- camperdave responding to MacAndrew on /.
 
Reply With Quote
 
Johannes Bauer
Guest
Posts: n/a
 
      09-07-2012
On 07.09.2012 18:13, Phil Carmody wrote:
> Johannes Bauer <(E-Mail Removed)> writes:
>> On 06.09.2012 13:41, Phil Carmody wrote:
>>
>>> #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0

>>
>> Boy we're in for a treat. You're a C++ wizard.
>>
>>> struct ivtlayout ivt = {
>>> INIT_IVT(0,0,0,0,0,0,0,0,1234,0)
>>> };
>>>
>>>>
>>>> I'll leave the C++ solution as an excersise to you. Hopefully you'll see
>>>> the point now.
>>>
>>> That took me 20 seconds. How many hours should I bill you for if you think
>>> it was hard work?

>>
>> You should apply for a software patent for your ingenious solution. It's
>> probably worth millions. Marvellous!

>
> If you're attempting to be patronising, I feel obliged to point out
> that it was you who was unable to come up with something and getting
> in a flap about how it was impossible in C++. I'm sorry if proving
> you wrong hurts your pride.


It is not possible in C++ to initialize structure members by their
names, which is the only nice solution that I know of. This doesn't hurt
my pride, it's a basic fact that you can read up in the C++ standard if
you find the time.

Your "solution" is having the exact same problem that a manually
initialized structure has: In a list of ~100 numbers, you need to set
exactly the correct one (i.e. count by hand).

Also, every definition file must include the union of all possible
vectors. You're making the problem much worse, not better. So if you're
really proposing this as a viable alternative you really have no idea at
all about how to write code that can be maintained well.

Regards,
Johannes

--
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?

> Zumindest nicht öffentlich!

Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$(E-Mail Removed)>
 
Reply With Quote
 
Johannes Bauer
Guest
Posts: n/a
 
      09-07-2012
On 07.09.2012 18:37, Phil Carmody wrote:
> Johannes Bauer <(E-Mail Removed)> writes:
>
>> On 06.09.2012 13:41, Phil Carmody wrote:
>>
>>> #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0

>>
>> Boy we're in for a treat. You're a C++ wizard.

>
> Only relatively. You've not set the standard particularly high.


You might want to look up the Dunning-Kruger effect.

> /* back in your C file */
> static const IVT<0,0,1234,0> ivt=0; /* IRQ2 initialised, no matter where it is in the array */


What if the selected architecture doesn't include the filled out vector
entry? Designated initializers: Compiler error. Your solution: Silent
discard.

What if a new architecture has a new vector entry that the others didn't
have? Designated initializers: Add it to the new definition structure.
You solution: Change all definition files to accomodate for it.

> phil@geespaz:tmp$ ./crap


At least you named it correctly.

Regards,
Johannes

--
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?

> Zumindest nicht öffentlich!

Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$(E-Mail Removed)>
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      09-09-2012
Johannes Bauer <(E-Mail Removed)> writes:
> On 07.09.2012 18:13, Phil Carmody wrote:
> > Johannes Bauer <(E-Mail Removed)> writes:
> >> On 06.09.2012 13:41, Phil Carmody wrote:
> >>
> >>> #define INIT_IVT(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9) v1,v2,v3,v6,v4,v7,v9,v5,v8,v0
> >>
> >> Boy we're in for a treat. You're a C++ wizard.
> >>
> >>> struct ivtlayout ivt = {
> >>> INIT_IVT(0,0,0,0,0,0,0,0,1234,0)
> >>> };
> >>>
> >>>>
> >>>> I'll leave the C++ solution as an excersise to you. Hopefully you'll see
> >>>> the point now.
> >>>
> >>> That took me 20 seconds. How many hours should I bill you for if you think
> >>> it was hard work?
> >>
> >> You should apply for a software patent for your ingenious solution. It's
> >> probably worth millions. Marvellous!

> >
> > If you're attempting to be patronising, I feel obliged to point out
> > that it was you who was unable to come up with something and getting
> > in a flap about how it was impossible in C++. I'm sorry if proving
> > you wrong hurts your pride.

>
> It is not possible in C++ to initialize structure members by their
> names, which is the only nice solution that I know of. This doesn't hurt
> my pride, it's a basic fact that you can read up in the C++ standard if
> you find the time.
>
> Your "solution" is having the exact same problem that a manually
> initialized structure has: In a list of ~100 numbers, you need to set
> exactly the correct one (i.e. count by hand).


Ah, sorry, yes, I was presuming the ability to count. If that doesn't apply,
you'll have a spot of bother in C++.

Phil
--
Regarding TSA regulations:
How are four small bottles of liquid different from one large bottle?
Because four bottles can hold the components of a binary liquid explosive,
whereas one big bottle can't. -- camperdave responding to MacAndrew on /.
 
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: GCC is re-implementing in C++ and C discarded Nomen Nescio C Programming 0 08-26-2012 10:34 AM
Re: GCC is re-implementing in C++ and C discarded Anonymous C Programming 10 08-26-2012 08:04 AM
Cisco VPN client, packets beeing discarded and bypassed seansan Cisco 3 09-24-2006 10:50 AM
discarded iterator.next() at interactive global scope doesn't bump interator?? Bengt Richter Python 2 09-04-2005 12:17 PM
Linker Message: "discarded section" Hartmut Sbosny C++ 2 05-29-2005 12:20 AM



Advertisments