Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Remember, there's a big difference between kneeling down and bending over. -- Frank Zappa


devel / comp.lang.c / binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers

SubjectAuthor
* binding reference of type ‘unsigned char&’ toM Powell
+- Re: binding reference of type ‘unsigned char&Ben Bacarisse
`- Re: binding reference of type ‘unsigned char&Keith Thompson

1
binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers

<4b3ea5a4-a02f-4cd2-9d0b-75c2f88fc721n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16631&group=comp.lang.c++#16631

  copy link   Newsgroups: comp.lang.c
 by: M Powell - Sun, 23 May 2021 23:26 UTC

Hi all, thought I had a decent handle on some aspects of C++ but this one has me stomped. I'm using an API (Driver that I cant change). For brevity here's a snippet

#include <iostream>
#include <sstream>
#include <string>

template < class In, unsigned int In_depth ,
class Out, unsigned int Out_depth >
class Driver {
public :
bool GetFromOutputFIFO ( Out& msg_data, unsigned int & msg_size ) {
//stuff
return true ;
}

bool GetFromOutputFIFO ( const void* msg_data, unsigned int & msg_size ) {
return GetFromOutputFIFO ( * (const In *) msg_data, msg_size ) ;
}
};

class Foo
{ Driver < unsigned char, 10, unsigned char, 10 > driver ;
public :
unsigned int WriteOut ( const unsigned int address, const unsigned char* buf,
const unsigned int len, const bool send )
{
unsigned int ll = len ;
driver.GetFromOutputFIFO ( buf , ll );
//driver.GetFromOutputFIFO ( const_cast < unsigned char* > ( buf ), ll );
//driver.GetFromOutputFIFO
//( const_cast < unsigned char* > ( const_cast < unsigned char* > ( buf ) ), ll );

}
};

int main()
{ }

The error
error: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers

How do I pass in buf to GetFromOutputFIFO ?

Thanks in advance

Re: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers

<8735udndgw.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16632&group=comp.lang.c++#16632

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Followup: comp.lang.c++
 by: Ben Bacarisse - Mon, 24 May 2021 01:10 UTC

M Powell <forumsmp@gmail.com> writes:

> Hi all, thought I had a decent handle on some aspects of C++ but this
> one has me stomped.

You've hit a bug in Google Groups that drops the ++ from the group name
so you've posted in comp.lang.c. I've replied, including comp.lang.c++
in the newsgroups and I've set a followup-to header. This may fix
things up.

> I'm using an API (Driver that I cant change).

One problem is in the class Driver. If you can't change that, you're
stuck.

> For brevity here's a snippet
>
> #include <iostream>
> #include <sstream>
> #include <string>
>
>
> template < class In, unsigned int In_depth ,
> class Out, unsigned int Out_depth >
> class Driver {
> public :
> bool GetFromOutputFIFO ( Out& msg_data, unsigned int & msg_size ) {
> //stuff
> return true ;
> }
>
> bool GetFromOutputFIFO ( const void* msg_data, unsigned int & msg_size ) {
> return GetFromOutputFIFO ( * (const In *) msg_data, msg_size ) ;
> }

Something is wrong here. These two overloads are inconsistent. In the
first, msg_data is not const and it is in the second.

It's not at all clear how this should be fixed. Ideally, you want
everything to be either const or not const.

The minimal change is to make the first msg_data a const Out &, but that
might be entirely wrong. The name of the function suggests it modifies
msg_data in which case it should not be const. That means the problem
is in the second overload and in the code below where things are
declared const that should not be.

> };
>
> class Foo
> {
> Driver < unsigned char, 10, unsigned char, 10 > driver ;
> public :
> unsigned int WriteOut ( const unsigned int address, const unsigned char* buf,
> const unsigned int len, const bool send )
> {
> unsigned int ll = len ;
> driver.GetFromOutputFIFO ( buf , ll );
> //driver.GetFromOutputFIFO ( const_cast < unsigned char* > ( buf ), ll );
> //driver.GetFromOutputFIFO
> //( const_cast < unsigned char* > ( const_cast < unsigned char* > ( buf ) ), ll );
>
> }
> };
>
> int main()
> {
> }
>
>
> The error
> error: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers
>
> How do I pass in buf to GetFromOutputFIFO ?

Start by saying exactly what the API is. That was we know what the
target functions look like.

--
Ben.

Re: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers

<87y2c53phw.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16633&group=comp.lang.c++#16633

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Followup: comp.lang.c++
 by: Keith Thompson - Mon, 24 May 2021 01:11 UTC

Google Groups is broken. If you post to comp.lang.c++, it quietly drops
the "++" and posts to comp.lang.c. (You *might* be able to write the
newsgroup name as "comp.lang.c%2b%2b"; can someone confirm that?)

I've cross-posted this reply to both newsgroups, with followups to
comp.lang.c++. Any followups to this should go to comp.lang.c++.

(Consider using a Usenet server such as news.eternal-september.org with
a newsreader such as Thunderbird or Gnus (the latter runs under Emacs).)

(I've posted new text at the top of the quoted text to be sure it isn't
missed. The usual convention here is for new text to go *below* quoted
text.)

M Powell <forumsmp@gmail.com> writes:
> Hi all, thought I had a decent handle on some aspects of C++ but this one has me stomped. I'm using an API (Driver that I cant change). For brevity here's a snippet
>
> #include <iostream>
> #include <sstream>
> #include <string>
>
>
> template < class In, unsigned int In_depth ,
> class Out, unsigned int Out_depth >
> class Driver {
> public :
> bool GetFromOutputFIFO ( Out& msg_data, unsigned int & msg_size ) {
> //stuff
> return true ;
> }
>
> bool GetFromOutputFIFO ( const void* msg_data, unsigned int & msg_size ) {
> return GetFromOutputFIFO ( * (const In *) msg_data, msg_size ) ;
> }
> };
>
> class Foo
> {
> Driver < unsigned char, 10, unsigned char, 10 > driver ;
> public :
> unsigned int WriteOut ( const unsigned int address, const unsigned char* buf,
> const unsigned int len, const bool send )
> {
> unsigned int ll = len ;
> driver.GetFromOutputFIFO ( buf , ll );
> //driver.GetFromOutputFIFO ( const_cast < unsigned char* > ( buf ), ll );
> //driver.GetFromOutputFIFO
> //( const_cast < unsigned char* > ( const_cast < unsigned char* > ( buf ) ), ll );
>
> }
> };
>
> int main()
> {
> }
>
>
> The error
> error: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers
>
> How do I pass in buf to GetFromOutputFIFO ?
>
> Thanks in advance

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor