Sunday, December 29, 2013

[OT] Re: Hope for your project - a little off topic.

Newsgroup: comp.lang.c++

Subject: [OT] Re: Hope for your project - a little off topic.

From: Paavo Helde <myfirstname@...>

Date: Sun, 29 Dec 2013 02:22:25 -0600



"Qu0ll" <Qu0llSixFour@...> wrote in

news:QrCdnTB7VPpkISLPnZ2dnUVZ_hOdnZ2d@...



> Are you serious - "there was no first human because humans evolved"?

> Even if your "theory" is correct, there still *must* have been the

> *first* human when the mutations produced the very first embryo which

> matched the full DNA profile of what we now term Homo sapiens in

> scientific nomenclature.



> This is a scientific fact and is true whether you believe in any of

> the Bible or not.



Do you realize that no two people share the same exact DNA (except

identical twins), so there is no exactly defined "DNA profile of Homo

Sapiens". The DNA of all people are just similar to some degree, that's

it.



Do you realize that DNA of a species is subject to constant mutations and

the DNA of people 3M years ago was quite different from humans today, so

the "DNA profile of Homo Sapiens" has inevitably changed over time.



Do you realize that there is no exact definition of any single species?

Species are defined only by distinction from other species, and this

definition depends on our knowledge about other species, which is vague

even about currently living ones, not to speak about historic ones. We

cannot know when Homo Sapiens branched off from the last other species

because this species is probably long dead and forgotten. If we talk

about currently living species then we are talking about humans and

chimps. If/when chimps die off, the branching point defined this way will

jump back many millions of years.



Do you realize that any tiny mutation in the DNA might be the starting

point of splitting a species into two, but this happens only very rarely?

You might want to call the person first possessing this mutation

Adam/Eve, but there are large problems with this, see above and below.

For starters, the mutation could have happened on the chimp side of the

branch, not ours.



Do you realize that this DNA branching point between living species can

shift back in time when some sub-branches die off? For example, if just a

bunch of chimps carrying some gene common with humans dies off, the

branching point between chimps and humans can jump back in time by many

generations.



So, you can come up with many definitions for "Adam", which seem quite

arbitrary and changing in time. As for your definition ("first person

matching the full DNA profile of what we now term Homo sapiens"), it even

does not make any sense. Please read up a book or two on the subject and

only then please come to tell us what is a "scientific fact" and what is

not.



Sorry I let me carried away into this thread. Trying to avoid that in

future...



Paavo







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160775-OT-Re-Hope-for-your-project-a-little-off-topic&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, December 28, 2013

4th bullet point in iso =?UTF-8?B?wqcxMi4xIHA1IGRvZXNuJ3QgbWE=?= =?UTF-8?B?a2Ugc2Vuc2UgdG8gbWU=?=

Newsgroup: comp.lang.c++

Subject: Re: 4th bullet point in iso =?UTF-8?B?wqcxMi4xIHA1IGRvZXNuJ3QgbWE=?= =?UTF-8?B?a2Ugc2Vuc2UgdG8gbWU=?=

From: Victor Bazarov <v.bazarov@...>

Date: Sat, 28 Dec 2013 08:57:19 -0500



On 12/28/2013 7:52 AM, johnkalane@... wrote:

> Maybe I'm missing something, but IMO the 4th bullet point in iso

> ??12.1

p5 is wrong:

>

> "X is a union and all of its variant members are of const-qualified

type (or array thereof),"



First off, it's the bullet point from the enumeration of the cases when

a "defaulted default constructor is defined as deleted". In other

words, if you don't declare the c-tor or define it, it's *deleted* by

the compiler (the compiler cannot create one for you), and one of the

situations is the union with all members const.



> Take for example the following snippet which compiles in Coliru and

Ideone (http://ideone.com/QW45u7), but it shouldn't as the defaulted

default constructor for the union should be deleted according to the

bullet point alluded above.



The bullet above does not apply in this case because you *explicitly*

declare the default constructor. The bullet only applies to the

_implicitly defined_ default c-tor.



>

> union T

> {

> const int y;

> const char c;

> const float z;

> T(int j) : y(j) {}

> T() = default;

> };

>

> int main()

> {

> T t;

> }

>

> I also don't understand why does the Standard disallow this code (see note in iso ??9.5 p2)

>

> struct S

> {

> int i;

> S() : i(1) {}

> };

>

> union T

> {

> S s;

> char c;

> };

>

> int main()

> {

> T t;

> }

>

> but allows this. What's the difference?

>

> struct S

> {

> int i;

> S() : i(1) {}

> };

>

> union T

> {

> S s;

> char c;

> T() {}

> };

>

> int main()

> {

> T t;

> }



The difference is that the union T in the latter (allowed) case is NOT

*implicit*.



V

--

I do not respond to top-posted replies, please don't ask







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160250-4th-bullet-point-in-iso-UTF-8-B-wqcxMi4xIHA1IGRvZXNuJ3QgbWE-UTF-8-B-a2Ugc2Vuc2UgdG8gbWU&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

4th bullet point in iso =?ISO-8859-1?Q?=A712=2E1_p5_does?= =?ISO-8859-1?Q?n=27t_make_sense_to_me?=

Newsgroup: comp.lang.c++

Subject: Re: 4th bullet point in iso =?ISO-8859-1?Q?=A712=2E1_p5_does?= =?ISO-8859-1?Q?n=27t_make_sense_to_me?=

From: "Alf P. Steinbach" <alf.p.steinbach+usenet@...>

Date: Sat, 28 Dec 2013 20:16:06 +0100



On 28.12.2013 17:50, johnkalane@... wrote:

>

> As far as I can understand the "T()" in the expression "T() = default;" refers

> to the defaulted (= default) default constructor T(), as explained here

> http://stackoverflow.com/a/7469608/1042389.



Stack Overflow is IMO a very unreliable authority, a Herb Schildt-land.

On SO an answer is selected as correct by the generally least competent

to judge it, namely the OP who, by asking, has demonstrated a clear lack

of competence. And this is so for ALL selected answers on SO, including

my own answers, and answers to my own questions, of course.



Rather than rely on SO, just assume that the standard's own definition

in §8.4.2/4 is the relevant one for use of that term in the standard:



* "Explicitly-defaulted functions and implicitly-declared functions are

collectively called /defaulted functions/, and the implementation shall

provide implicit definitions for them (12.1 12.4, 12.8), which might

mean defining them as deleted"



About your original question I'm less sure, but it does look like either

compiler bugs or a defect in the standard, or perhaps both.



I therefore recommend posting this to the mailing list about standards

defects (it has about the same role now as the defunct comp.std.c++),

namely <url:

http://groups.google.com/a/isocpp.org/group/std-discussion/>, and/or to

the comp.std.c++ sister group comp.lang.c++.moderated, which forked from

this group in the 90's, and which unlike comp.std.c++ is still limping

along, not quite dead.





Cheers & hth.,



- Alf









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160348-4th-bullet-point-in-iso-ISO-8859-1-Q-A712-2E1_p5_does-ISO-8859-1-Q-n-27t_make_sense_to_me&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

=?ISO-8859-1?Q?Re=3A_4th_bullet_point_in_iso_=A712=2E1_p5_doesn=27t_make_s?= =?ISO-8859-1?Q?ense_to_me?=

Newsgroup: comp.lang.c++

Subject: =?ISO-8859-1?Q?Re=3A_4th_bullet_point_in_iso_=A712=2E1_p5_doe sn=27t_make_s?= =?ISO-8859-1?Q?ense_to_me?=

From: johnkalane@...

Date: Sat, 28 Dec 2013 08:42:59 -0800 (PST)



Thanks for your reply, but I have to disagree.



"The bullet above does not apply in this case because you *explicitly*

declare the default constructor. The bullet only applies to the

_implicitly defined_ default c-tor."



As far as I can understand the term "defaulted default constructor" refers exactly to the defaulted (= default) default constructor T() as is explained here (http://stackoverflow.com/a/7469608/1042389). In other words, the "T()" in the expression "T() = default;" refers to the implicitly defined default constructor.









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160268-ISO-8859-1-Q-Re-3A_4th_bullet_point_in_iso_-A712-2E1_p5_doesn-27t_make_s-ISO-8859-1-Q-ense_to_me&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Is It Possible...?

Newsgroup: comp.lang.c++

Subject: Is It Possible...?

From: mrc2323@...

Date: Sat, 28 Dec 2013 07:31:50 -0700



To "template-ize" a class/struct sort override? I have the following

structure:

struct RelayTeamType

{

time_t totalTime; // Total Time

int bib1, bib2; // Bib# #1 & Bib# #2

int numFins; // # Finishers

char ttc; // Team Type Code

string rtCode, rtTeamName;

string sortKey; // derived sort key

bool operator<(const RelayTeamType &a) const

{

return sortKey < a.sortKey;

}

} extern rtWork;

extern vector<RelayTeamType> rtVect;

extern vector<RelayTeamType>::iterator relIter;



Currently, I'm constructing the "sortKey" variable by passing through

the entire vector and using different variables in the struct (e.g.

"rtCode" or "totalTime", etc.), followed by the sort. This is simple

enough, but it takes processing time I want to avoid.

I'd like to be able to sort the vector on different fields, and it

would be nice if I could do it via a "template" interface. Is this

possible somehow? TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160251-Is-It-Possible&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Wednesday, December 25, 2013

The "widget" problem

Newsgroup: comp.lang.c++

Subject: The "widget" problem

From: Tom <tflynn@...>

Date: Tue, 24 Dec 2013 12:27:00 GMT



I don't know if that's the right name for this but it's refers to the

situation that might arise in a GUI framework where classes are used to

represents widgets like buttons and text boxes. Member functions of the

widget like button::press() are called on input. A user defined widget

may contain other widgets as members (for instance a file browsing

dialog has buttons, lists, textboxes, etc..), and may wish to do some

processing of a button press after the original widget has done its

work. Every GUI framework must at some point decide how this

capability is made available to the end user of the library.



The mostly widely used OO GUI framework for C++ is Qt enables this with

their "signals and slots" mechanism. This involves introducting new

syntax into the code and preprocessing the source with the moc (meta

object compiler) system. This doesn't prevent people from being

productive with Qt of course, but it raises the question (which I'm sure

has been addressed before) of how to do this with pure C++ in a

typesafe manner while preserving the ability to seperately compile

widgets. Also we want the process of setting up callbacks to be as

simple as e.g. passing function pointers.



Part of the issue is that one cannot make use of a pointer to a member

function without an instance of the class itself. Yet we don't want

any previously defined widgets to know anything about our new widget

or have to be recompiled,



Let me know what you think of this solution. Here "button"

and "mywidget" are two widgets in the system, mywidget contains a

button and the wants to receive the press events of the button.



class cb_base{

public:

virtual void call () = 0;

};



template<class T>

struct cb_c {



template<void (T::*fn)()>

class cb_t : public cb_base{

public:

T * t;



cb_t(T * _t):t(_t){}



virtual void call(){

((*t).*(fn))();

}

};



};



class button{

public:

cb_base * callback;



button(cb_base * _callback=NULL):callback(_callback){}



void press(){

printf("In press\n");

if(callback) callback->call();

}

};





class mywidget{

public:

typedef cb_c<mywidget> cb_type;



button * b;



mywidget(){

b = new button(new handler_cb(this));

}



void my_handler(){

printf("In my handler\n");

}



typedef cb_type::cb_t<&mywidget::my_handler> handler_cb;

};



/* An example of calling the press event, which would be done by the

windowing system */

int main(){ mywidget m; m.b->press(); return 0; }





-Thomas Flynn









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?158342-The-widget-problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, December 23, 2013

passing null as parameter to reference to an object

Newsgroup: comp.lang.c++

Subject: passing null as parameter to reference to an object

From: shaan <shaanxxx@...>

Date: Mon, 23 Dec 2013 02:51:56 -0800 (PST)



I have following function:

void myfunction (int &a , bool g )

{

if(g)

{

int k = a;

}

}





int main()

{

int * ptr = NULL;

myfunction(*ptr, false);



}



Is passing null to a reference legal? What standard has to say about this ?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?157612-passing-null-as-parameter-to-reference-to-an-object&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, December 19, 2013

A question of interface

Newsgroup: comp.lang.c++

Subject: A question of interface

From: Daniel <danielaparker@...>

Date: Tue, 17 Dec 2013 20:07:58 -0800 (PST)



This isn't a question about a language issue, but a question about the design of

an interface, hopefully not entirely off topic as the features of the language and language conventions both constrain design.



Consider a json class, called json, that internally stores an array of values,

or an object of name value pairs, or a bool, string, numeric or null value (the

actual internal representation is unimportant.) Constructors for string, bool,

double and int values can naturally be provided as json(const string& val),

json(bool val), json(double val), and json(int val). Construction of a null

value can use the copy constructor and a json::null prototype.



But what to do about constructing object (collection of name-value pairs) and

array values?



Approach 1:



json obj(json::an_object);

// Constructs a json value of type object from an empty object prototype

// (or equivalently, given an enum type indicator)



obj["first_name"] = "John";

obj["last_name"] = "Smith";



// Any array operations on obj would throw



json arr(json::an_array);



arr.add("John");



// Any object operations on arr would throw



Approach 2:



json obj = json::make_object();



json arr = json::make_array();



Approach 3:



json val;

// Constructs a json object of undefined type (not a valid json state),

// or alternatively a null type (a valid json type), and delay until the first

// operation to fix the type



That is, if the first operation is



val["age"] = 50;



val becomes an object, and subsequent array operations would throw, but if the

first operation is



val.add(50);



val becomes an array, and subsequent object operations would throw.



Approach (3) is I believe the most popular in the open source implementations,

it's probably a little more javascript like, users seem to like its

simplicity, but at the same time the user forums have users who construct



json val;



add no members, and are surprised that



std::cout << val << std::endl;



produces "null" rather than the empty object notation "{}".



Then again, if we take approach (1) or (2), what to do with the default

constructor? Letting it be null type is probably okay, it's desirable to have a

default constructor that's lightweight, but a null default doesn't provide much

useful functionality for the user.



Anyway, if anyone has any thoughts, with consideration to the "principle of

least amazement" and most expected C++ convention, I'd be grateful for feedback.



Thanks,

Daniel

















via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?153642-A-question-of-interface&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Wednesday, December 18, 2013

typedef of class vs class?

Newsgroup: comp.lang.c++

Subject: typedef of class vs class?

From: Ed Anson <EdAnson@...>

Date: Wed, 18 Dec 2013 19:22:56 -0500



As I read the standard (and various texts on the language) a typedef of

a class is simply a synonym for the class name. So I am surprised that

the following code fails to compile on any C++ compiler I have access to:



class bar;



template <class T>

class foo

{

public:

foo(const T& v) : m(v) {}

T m;

};



typedef foo<int> bar;





Gcc 4.6.3 gives the following error [as slightly mangled by putty]:

TypedefAnomaly.cpp:11:18: error: conflicting declaration âtypedef class

foo<int> barâ

TypedefAnomaly.cpp:1:7: error: âstruct barâ has a previous declaration

as âstruct barâ



Other compilers claim that the forward declaration of bar is

incompatible with the typedef, but don't say why. Is there some fine

point in the C++ standard that I am missing? Must be, since it's

unlikely that all the compilers have the same bug.



/Ed









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?154605-typedef-of-class-vs-class&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, December 17, 2013

My two string classes could be "templatized" into one, but for one problem...

Newsgroup: comp.lang.c++

Subject: My two string classes could be "templatized" into one, but for one problem...

From: DSF <notavalid@...>

Date: Mon, 09 Dec 2013 00:52:07 -0500



Hello group!



Under Windows, I have two string classes: FStringA and FStringW, as

per Windows' naming convention. I have done a lot of work recently on

the Wide version and decided to update the ANSI version. As I sat

there with two windows synchronized, looking for updates from W to

apply to A, it occurred to me that these lengthy classes are identical

save for two differences, and would be ideal as a template. That way

only one code set to update!



The first difference is simple: FStringA uses char whilst FStringW

uses wchar_t. If that were the only difference, it would be a piece

of cake. But it's never that simple, is it?



The second difference is the plethora of C sting calls these classes

use. I've rewritten the parts of the string RTL that I use, both for

a speed increase and to handle wide strings. I preface a 'd' to the

front since 'str' is reserved for the RTL. This leaves me with many

'dstringsomethingA' and 'dstringsomethingW' calls.



But how do I get the compiler to determine which call to make when

building the template into code? I could put preprocessor if/else

around all the d...A/Ws. That is actually built-in to them (based on

the definition of UNICODE), but the implementation seems sloppy. I

would have to preface each creation with preprocessor code such as:



// This is off the top of my head and I'm not even sure it would work,

// but it's clumsy anyway.

// FStr being the template class

typedef FStr<char> FStringA;

typedef FStr<wchar_t> FStringW;



#ifdef UNICODE

#define UCFLAG

#undef UNICODE

#endif

FStringA title;

#ifdef UCFLAG

#undef UCFLAG

#define UNICODE

#endif



#ifndef UNICODE

#define UCFLAG

#define UNICODE

#endif

FStringW name;

#ifdef UCFLAG

#undef UCFLAG

#undef UNICODE

#endif



Ugh!



So it's the old question of determining the type at compile time,

perhaps simplified because there are only two choices. Also, it would

be nice to throw a compilation error if the type is not one of the

two.



Any ideas?



TIA!

"'Later' is the beginning of what's not to be."

D.S. Fiscus







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?146527-My-two-string-classes-could-be-templatized-into-one-but-for-one-problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, December 16, 2013

templates help

Newsgroup: comp.lang.c++

Subject: templates help

From: Devender Rao <mdevender@...>

Date: Mon, 16 Dec 2013 05:48:57 -0800 (PST)



I am having code from a library as shown below. I am not able to understand the purpose of "class ErrorAccessingPrivilegedAttribute;". Not sure how it works.





#define FAPI_ATTR_GET(ID, PTARGET, VAL) \

(fapiFailIfPrivileged<fapi::ID##_Privileged>(), \

fapiCheckIdType<fapi::ID##_Type>(ID, VAL), \

ID##_GETMACRO(ID, PTARGET, VAL))



template<typename T> inline void fapiCheckIdType(AttributeId, T &) {}



class ErrorAccessingPrivilegedAttribute;

template<const bool PRIVILEGED> void fapiFailIfPrivileged()

{

ErrorAccessingPrivilegedAttribute();

}

template <> inline void fapiFailIfPrivileged<false>() {}



Thank you in advance for any help.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?152099-templates-help&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, December 15, 2013

Repost: Does anyone have a workaround for this gcc4.3 issue?

Newsgroup: comp.lang.c++

Subject: Repost: Does anyone have a workaround for this gcc4.3 issue?

From: huili80@...

Date: Sun, 15 Dec 2013 14:24:39 -0800 (PST)



The code attached compiles with gcc4.8 and above, however, gcc4.3 fails to compile, and i hope to find a workaround for gcc4.3 since that's currently the only compiler available to me (at work, that is).



The non-compile appears to be a gcc4.3 issue (bug maybe?), where a substitution failure, i.e., the instantiation of test<X> when calling f<X>(0), is mistakenly being treated as an error.



As for the code itself, since i'm using gcc4.3 which doesn't have c++11, therefore no decltype, so i had to use the gcc extension typeof, which is really the only thing non-standard about it.



I'd very much appreciate any help. Thanks!



code here:

-------------------------------

template < typename T > T& obj();



template < typename T, typename=typeof(obj<T>().memfun()) >

struct test {};



template < typename T > test<T> f(int){}



template <typename> char f(...){}



struct X

{

void memfun(int){};

};



int main()

{

f<X>(0);

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?151692-Repost-Does-anyone-have-a-workaround-for-this-gcc4-3-issue&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Does anyone have a workaround for this gcc4.3 issue?

Newsgroup: comp.lang.c++

Subject: Does anyone have a workaround for this gcc4.3 issue?

From: huili80@...

Date: Sun, 15 Dec 2013 12:57:02 -0800 (PST)



Code is as follows. It's legal c++ code, however doesn't compile with g++4.3.

Would really appreciate if anyone has a workaround!! Thanks!



-----------------------------------------------



template < typename T > T& obj();



template < typename T, typename=typeof(obj<T>().memfun()) >

struct test {};



template < typename T > test<T> f(int){}



template <typename> char f(...){}



struct X

{

void memfun(int){};

};



int main()

{

f<X>(0);

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?151634-Does-anyone-have-a-workaround-for-this-gcc4-3-issue&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, December 13, 2013

More swearing was: Islam is the fastest growing religion ...

Newsgroup: comp.lang.c++

Subject: More swearing was: Islam is the fastest growing religion ...

From: woodbrian77@...

Date: Fri, 13 Dec 2013 12:50:03 -0800 (PST)



On Friday, December 13, 2013 2:38:06 PM UTC-6, Mr Flibble wrote:

>



Please don't swear here.











via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?150493-More-swearing-was-Islam-is-the-fastest-growing-religion&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, December 12, 2013

DSR and OpenSSL question

Newsgroup: comp.lang.c++

Subject: DSR and OpenSSL question

From: Friend <hirenshah.05@...>

Date: Thu, 12 Dec 2013 10:05:00 -0800 (PST)



Hi All,



I configured OpenSSL as server. I create SSL object, SSL_set_fd and than SSL_accept.



I understand after SSL_accept, I can just do SSL_read/SSL_write with SSL object (which is bind to FD).



Is it possible to do SSL_set_fd again after SSL_accept. Everything under SSL object should remain same (it has already pass SSL handshake), only FD number is changed.



I have this requirement because its DSR (Direct Server Return architecture). Where SSL handshake will happen on Server 1 and than DSR to Server 2 and Server 2 does communication with client.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?149592-DSR-and-OpenSSL-question&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

How is it that this code seems to work?

Newsgroup: comp.lang.c++

Subject: How is it that this code seems to work?

From: bobl0456@...

Date: Tue, 10 Dec 2013 13:34:25 -0800 (PST)



A student submitted this code:



bool isPalindrome(string word)

{

string::iterator forwardIt = word.begin();

string::reverse_iterator reverseIt = word.rbegin();



while (forwardIt != word.end())

{

if (*forwardIt != *reverseIt)

{

return false;

}

else

{

++forwardIt;

++reverseIt;

}

}

}



The function seems to work, even though I don't believe it should.



Specifically, I believe the code should be instead:



bool isPalindrome(string word)

{

string::iterator forwardIt = word.begin();

string::reverse_iterator reverseIt = word.rbegin();



while (forwardIt != word.end())

{

if (*forwardIt != *reverseIt)

{

return false;

}

else

{

++forwardIt;

++reverseIt;

}

}



return true; // THE CHANGE I MADE

}



The if statement that invokes this function appears to work correctly:



if (isPalindrome(substring))



Does anyone have a clue as to how this works despite the missing return statement?



Thanks in advance.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?148139-How-is-it-that-this-code-seems-to-work&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Wednesday, December 11, 2013

this pointer mapped to a register?

Newsgroup: comp.lang.c++

Subject: this pointer mapped to a register?

From: W Karas <wkaras@...>

Date: Wed, 11 Dec 2013 12:30:01 -0800 (PST)



Is it typically the case that, in object code generated from C++ source, the "this" pointer is mapped to a CPU register? And passed in member function calls in a register?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?148974-this-pointer-mapped-to-a-register&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Proposed Standard Change: inline this

Newsgroup: comp.lang.c++

Subject: Proposed Standard Change: inline this

From: W Karas <wkaras@...>

Date: Wed, 11 Dec 2013 09:34:41 -0800 (PST)



An instance x of class X could be declared with this syntax:



inline this X x;



This would potentially affect the object code generated a call x.mem(...), mem() a member function of X which was defined inline. The compiler could simply inline the function call. But if it didn't, the above declaration would cause the compiler to "consider" generating and calling object code for mem() with the hard-coded address of x in place of the (eliminated) implied "this" parameter. The compiler could further "consider" cascading this behavior to member functions, defined inline, that are directly or indirectly called by mem().



It's not unusual for classes to have only one instance of the class in a program. It this case, it seems wasteful to be passing the "this" parameter over and over with a never-changing value. One can make all class members static, or use a namespace "pseudo-class". But that seems a akin to using macros as alternatives to inline functions. Object code optimization should (ideally) either be automatic, or only require a minimal hint added to source code describing logical behavior. Also, this facility might be a useful optimization in cases where there are a small number of instances (greater than 1) of X in the program.



If you find this syntax unaesthetic, I agree, I'm very open to suggestions for alternatives.



On the other hand, I suspect, for typical contemporary architectures, generated object code may use a "dedicated" register for the "this" pointer. In which case, this optimization would save the execution of few/no instructions.



Another point against is that this change, like templates, would drive more Java-esqe class declarations with all the member functions defined inline.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?148867-Proposed-Standard-Change-inline-this&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, December 9, 2013

public member variable vs. get/set functions

Newsgroup: comp.lang.c++

Subject: public member variable vs. get/set functions

From: W Karas <wkaras@...>

Date: Mon, 9 Dec 2013 14:39:12 -0800 (PST)



The main purpose of private members is to provide some level of compile time checking for the rules of use of an object that must be followed, in order to keep the object in a valid state.



Given that, a private member variable with (simple, public) get/set functions just seems like pointless code bloat. It provides no additional protection against putting the object in a bad state than having the member variable be public.



Some (perhaps Smalltalk fans) argue that it's very rare that simply setting a member variable should properly be part of an objects public interface. Therefore, it's best to follow the rule of thumb that all member variables should be private.



It can also be argued that it is often important, for code maintenance, to be able to quickly identify external changes to a member variable, as opposed to read access to the variable. A counter-argument is that some sort of code browsing tool should be available to prevent the need to bloat the code in order to highlight this distinction.



In some cases, it could be likely that the get/set function would eventually do more than simple get/set a single member variable. That would be a clear case where keeping the member variable private would be the correct choice. But, as I have seen Dr. Bjarne argue, it's easy to go overboard with future-safety.



Your thoughts?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?147271-public-member-variable-vs-get-set-functions&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, December 8, 2013

C++ hardware library for (small) 32-bit micro-controllers

Newsgroup: comp.lang.c++

Subject: C++ hardware library for (small) 32-bit micro-controllers

From: Wouter van Ooijen <wouter@...>

Date: Wed, 04 Dec 2013 19:45:34 +0100



(posted to comp.lang.c++, comp.arch.embedded, yahoo-groups/lpc2000)



I am working on a portable C++ hardware library for real-time

applications on small (but still 32-bit) micro-controllers. My typical

(and current only) target is the Cortex M0 LPC1114FN28 (4k RAM, 32K

Flash) using GCC. Efficiency is very important, in run-time, RAM use,

and ROM use. The typical restrictions for small microcontrollers apply:

no RTTI, no exceptions, and no heap (or at most just an allocate-only heap).



So far I have found nice and efficient abstractions for I/O pins and I/O

ports (using static class templates), implemented those on the LPC1114,

and used these abstractions to implement protocols (I2C, SPI) and

interfaces for some external chips like 74HC595 and MCP23017.



Like any would-be author of a serious piece of work I am looking for an

adience to read, test, critisize (ridicule if necessary), maybe even

contribute, and eventually use my work.



To get a idea of what I want to make, a very initial version can be

found at http://www.voti.nl/hwlib



Any takers?



If this is all too abstract, I have a more concrete question, mainly for

C++ architects. For I/O pins and ports I use class templates with (only)

static functions. This matches well with reality (the hardware circuit

is generally fixed), and is much more efficient than using inheritance

and virtual functions.



However, I am now working on graphics for small LCD screens. At the

lowest level (configuring an LCD driver for the size of the LCD and the

pins used) the static-class-template approach is fine. But at some level

the higher abstractions using the screen (for instance a subscreen,

button, etc.) must be more dynamic and created ad-hoc. So somewhere

(probably at multiple levels in the abstraction tree) I must make a

transition from static class templates to the classic objects in an

inheritance tree with virtual functions. Does anyone have any experience

with such a dual hierarchy? One very stupid but basic problem is naming:

a template and a class can't have te same name, so when the natural name

would for instance be 'subframe', who gets that name, the template, the

class, or neither?



Wouter van Ooijen











via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?143091-C-hardware-library-for-(small)-32-bit-micro-controllers&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, December 7, 2013

Native Aspect-oriented programming in C++

Newsgroup: comp.lang.c++

Subject: Native Aspect-oriented programming in C++

From: =?ISO-8859-1?Q?C=F4me_David?= <davidbrcz@...>

Date: Sat, 07 Dec 2013 21:45:51 +0100



Hello everyone.



I've been wondering why there have never been any proposal to a native

support for Aspect-oriented programming in the C++ core.



I think this tool would be a nice improvement and could be used for

instance to :

* ensure classes' invariant

* logging purpose

* etc ..



Does anyone has an explanation ?



Thank you !

David Come.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?145939-Native-Aspect-oriented-programming-in-C&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, December 6, 2013

Want to debug this?

Newsgroup: comp.lang.c++

Subject: Want to debug this?

From: woodbrian77@...

Date: Fri, 6 Dec 2013 15:06:24 -0800 (PST)



Maybe you can motivate me to debug the following scenario:



Gcc-built version of my middle tier asserts



assert(!pendingTransactions.empty());



in transitional context.



If I start the back tier, start clang-built middle tier

and then run some tests, everything works fine.



If I start the back tier, start gcc-built middle tier

and then run some tests, everything again works fine.



If I start the back tier, start clang-built middle tier,

run some tests, stop clang-built middle tier and start

gcc-built middle tier and run the tests, it asserts as

mentioned.



If I start the back tier, start gcc-built middle tier,

run some tests, stop gcc-built middle tier and start

clang-built middle tier and run some tests everything

works fine. If I go on and stop clang-built middle

tier and start gcc-built middle tier and run tests,

the assert happens.



I'm not sure if it's worth debugging. I'm using gcc

4.8.1 and clang 3.3 on Linux. I have a machine that

has gcc 4.8.2 on it, but haven't tested it on there.

I've been thinking of moving to newer software (OS

and compilers) on the machine I have the problem on,

so the "problem" might go away that way too.





Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?145397-Want-to-debug-this&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, December 5, 2013

Function overloading question

Newsgroup: comp.lang.c++

Subject: Function overloading question

From: blaz.bratanic@...

Date: Thu, 5 Dec 2013 02:40:01 -0800 (PST)



#include <iostream>

#include <vector>

#include <list>



template <typename T>

void foo(T a) {

std::cout << "General" << std::endl;

}



template <typename T>

void foo(std::vector<T> a) {

std::cout << "Vector" << std::endl;

}



int main() {

std::vector<int> v = {1,2,3};

foo(v); // vector



std::list<int> l = {1,2,3};

foo(l); // general

}



Could someone explain does the call to foo not result in an ambiguous call?



Probably the question is, why the compiler prefers

foo<int> over foo<std::vector<int>>?



thanks







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?143578-Function-overloading-question&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, December 3, 2013

Building a Large Container

Newsgroup: comp.lang.c++

Subject: Building a Large Container

From: mrc2323@...

Date: Mon, 2 Dec 2013 17:16:01 -0700



One of my applications running very slowly, due to high volume of

data. I'm currently using an STL map to store the data, and I'm trying

to convert to STL vector for processing.

The basic operation is that I could be loading some of the container

from one source (or not), but then I am definitely loading data from a

second source - and modifying existing information if it came from the

first source. The data is accessed by an integer scalar variable (see

"bibNum", below). Here's the (new) data structure:



typedef struct ChipRec

{

int bibNum; // Bib#

int dbeAge, ndfAge, gruAge;

char dbeGender, ndfGender, gruGender;

char dbeRCode, ndfRCode, gruRCode;

bool timeWritten, dbAdd;

bool dbeMatched, ndfMatched, gruMatched;

time_t startDelta;

time_t clockTime;

string dbeName, gruName;

string strAddress, strCity, strDoB;

[etc.]

} ChipData;

extern ChipData chipWork;

typedef vector<ChipRec> CRVect;

extern CRVect chipVect;

extern CRVect::iterator chipIter;



I planned to sort my container and use a binary search to determine

if I was adding a new object of modifying an existing one. That

technique won't work, as I'd have to sort the container each time I add

an object (very slow!). The binary search won't help me, because it

doesn't return an iterator to the matched object for possible

modification.

It seems using an STL vector isn't a solution...8<{{ The STL map

works, but for 30,000 objects takes about 20 minutes to go through this

process.

Am I missing something (a different container, perhaps) that would

support my application in an efficient way? Thoughts? TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?141643-Building-a-Large-Container&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, December 2, 2013

How am I supposed to define this namespace variable?

Newsgroup: comp.lang.c++

Subject: How am I supposed to define this namespace variable?

From: "A" <a@...>

Date: Mon, 2 Dec 2013 18:57:01 +0100



Header file:



namespace MyNameSpace

{

extern const wchar_t CharArr[];

extern const int IntArr[];

}



Src file:



const wchar_t MyNameSpace::CharArr[] = "abc";

const int MyNameSpace::IntArr[5] = { 1,2,3,4,5};





-- the problem - when I access these variables I get a runtime error as if I

was trying to access undefined part of memory. But I don't understand why...

variable should be defined and debugger sees them.











via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?140882-How-am-I-supposed-to-define-this-namespace-variable&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums