public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* compiler confusion?
@ 2003-04-23 16:03 Ivan Molella
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Molella @ 2003-04-23 16:03 UTC (permalink / raw)
  To: gcc

I' have the follwing problem:


I' have the following assertion class:

template<class Excp>
class Assert
{
public:

typedef Excp exception_throwed;

Assert(bool val, const char* msg_throwed, long code)
: value(val), message(msg_throwed), excCode(code)
{ }

Assert(bool val, string msg_throwed, long code)
: value(val), message(msg_throwed), excCode(code)
{ }

void do_assert()
{
if (!(value)) throw exception_throwed(message, excCode);
}


private:

bool value;
const string message;
long excCode;
};

when i use this assertion in the following code:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31> Assert<telnetClientException>((checkProcessStatus() == 
telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}

i have the following error:

telnetClient.cpp: In member function `void
telnetClient::init(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, char* const*, char* const*, int)':
telnetClient.cpp:31: parse error before `==' token


while if i do:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31> Assert<telnetClientException>((this->checkProcessStatus() == 
telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}


compilation is done without any error.

I'm using gcc 3.2.

What's the matter with the first expression?


Thanks in advance.

Ivan




checkProcessStatus is so defined:

bool
telnetClient::checkProcessStatus()
{
if (task.isAlive()==telnetClient::process_terminated){
return telnetClient::process_terminated;
}

return telnetClient::process_running;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: compiler confusion?
  2003-04-24 15:12 Gareth McCaughan
@ 2003-04-25  9:00 ` wilson k.j
  0 siblings, 0 replies; 5+ messages in thread
From: wilson k.j @ 2003-04-25  9:00 UTC (permalink / raw)
  To: Gareth McCaughan; +Cc: gcc


But why it heppens only when you pass it  ( g() == 100
) to constructors. I can have a method in struct A
with takes bool as argument, and invoke the method
like this,
objectOfA.myMethod( ( g() == 100 ) )


Wilson

--- Gareth McCaughan <gmccaughan@synaptics-uk.com>
wrote:
> Here's a stripped-down version of your code that
> exhibits
> the same problem.
> 
>     struct A {
>       A(bool x) {}
>     };
>     
>     struct C {
>       void f();
>     };
>     
>     static int g() { return 1; }
>     void C::f() {
>       A(g() == 100);
>     }
> 
> Here's what I think is going on: the compiler is
> seeing
> that line "A(g() == 100);" as a declaration of a
> function
> called g, returning a value of type A. The same as
> if it said
> "A g() == 100;". And, of course, when it gets to the
> "==",
> that stops making any sense :-).
> 
> I'm not enough of a C++ standards guru to know
> whether
> this behaviour is (1) allowed and/or (2) required.
> It's
> weird, certainly, but there are other almost equally
> ludicrous interpretations that *are* required by the
> standard. For instance, here's an example from Scott
> Meyers's
> "Effective STL".
> 
>     ifstream dataFile("ints.dat");
>     list<int> data(istream_iterator<int>(dataFile),
>                    istream_iterator<int>());
> 
> Perhaps contrary to appearances, what this does is
> to declare a function called "data" taking two
> arguments: the first is of type
> istream_iterator<int>
> and is named "dataFile", and the second is of type
> "pointer to function from void to
> istream_iterator<int>"
> and has no name. :-)
> 
> -- 
> g
> 
> 
> 


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: compiler confusion?
@ 2003-04-24 15:12 Gareth McCaughan
  2003-04-25  9:00 ` wilson k.j
  0 siblings, 1 reply; 5+ messages in thread
From: Gareth McCaughan @ 2003-04-24 15:12 UTC (permalink / raw)
  To: Ivan Molella; +Cc: gcc

Here's a stripped-down version of your code that exhibits
the same problem.

    struct A {
      A(bool x) {}
    };
    
    struct C {
      void f();
    };
    
    static int g() { return 1; }
    void C::f() {
      A(g() == 100);
    }

Here's what I think is going on: the compiler is seeing
that line "A(g() == 100);" as a declaration of a function
called g, returning a value of type A. The same as if it said
"A g() == 100;". And, of course, when it gets to the "==",
that stops making any sense :-).

I'm not enough of a C++ standards guru to know whether
this behaviour is (1) allowed and/or (2) required. It's
weird, certainly, but there are other almost equally
ludicrous interpretations that *are* required by the
standard. For instance, here's an example from Scott Meyers's
"Effective STL".

    ifstream dataFile("ints.dat");
    list<int> data(istream_iterator<int>(dataFile),
                   istream_iterator<int>());

Perhaps contrary to appearances, what this does is
to declare a function called "data" taking two
arguments: the first is of type istream_iterator<int>
and is named "dataFile", and the second is of type
"pointer to function from void to istream_iterator<int>"
and has no name. :-)

-- 
g



^ permalink raw reply	[flat|nested] 5+ messages in thread

* compiler confusion?
@ 2003-04-23 15:46 Ivan Molella
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Molella @ 2003-04-23 15:46 UTC (permalink / raw)
  To: gcc

I' have the follwing problem:


I' have the following assertion class:

template<class Excp>
class Assert
{
public:

typedef Excp exception_throwed;

Assert(bool val, const char* msg_throwed, long code)
: value(val), message(msg_throwed), excCode(code)
{ }

Assert(bool val, string msg_throwed, long code)
: value(val), message(msg_throwed), excCode(code)
{ }

void do_assert()
{
if (!(value)) throw exception_throwed(message, excCode);
}


private:

bool value;
const string message;
long excCode;
};

when i use this assertion in the following code:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31> Assert<telnetClientException>((checkProcessStatus() == 
telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}

i have the following error:

telnetClient.cpp: In member function `void
telnetClient::init(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, char* const*, char* const*, int)':
telnetClient.cpp:31: parse error before `==' token


while if i do:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31> Assert<telnetClientException>((this->checkProcessStatus() == 
telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}


compilation is done without any error.

I'm using gcc 3.2.

What's the matter with the first expression?


Thanks in advance.

Ivan




checkProcessStatus is so defined:

bool
telnetClient::checkProcessStatus()
{
if (task.isAlive()==telnetClient::process_terminated){
return telnetClient::process_terminated;
}

return telnetClient::process_running;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* compiler confusion?
@ 2003-04-23 13:29 Ivan Molella
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Molella @ 2003-04-23 13:29 UTC (permalink / raw)
  To: gcc


i' have the follwing problem:

I' have the following assertion class:

template<class Excp>
class Assert
{
         public:

                 typedef Excp exception_throwed;

                 Assert(bool val, const char* msg_throwed, long code)
                         : value(val), message(msg_throwed), excCode(code)
                 { }

                 Assert(bool val, string msg_throwed, long code)
                         : value(val), message(msg_throwed), excCode(code)
                 { }

                 void  do_assert()
                 {
                 if (!(value)) throw exception_throwed(message, excCode);
                 }


         private:

                 bool value;
                 const string message;
                 long excCode;
};

when i use this assertion in the following code:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31>             Assert<telnetClientException>((checkProcessStatus() == 
telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}

i have the following error:

telnetClient.cpp: In member function `void
    telnetClient::init(std::basic_string<char, std::char_traits<char>,
    std::allocator<char> >, char* const*, char* const*, int)':
telnetClient.cpp:31: parse error before `==' token


while if i do:

void
telnetClient::init(const string pTelnetProg,char* const* pArgs,char* 
const*pEnv,int _timeout) {
.....
31>             Assert<telnetClientException>((this->checkProcessStatus() 
== telnetClient::process_running),"[MM CO=EBEX_TELNET_L0016 
MM]",PROCESS_DOWN_ERROR).do_assert();
....

}


compilation is done without any error.

What's the matter with the first expression?

Thanks in advance.


checkProcessStatus is so defined:

bool
telnetClient::checkProcessStatus()
{
         if (task.isAlive()==telnetClient::process_terminated){
                 return telnetClient::process_terminated;
         }

         return telnetClient::process_running;
}



Ci sono 10 categorie di persone:
quelli che sanno contare in binario e tutti gli altri.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-04-25  7:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-23 16:03 compiler confusion? Ivan Molella
  -- strict thread matches above, loose matches on Subject: below --
2003-04-24 15:12 Gareth McCaughan
2003-04-25  9:00 ` wilson k.j
2003-04-23 15:46 Ivan Molella
2003-04-23 13:29 Ivan Molella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).