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