Global Sources
EE Times - IndiaWebsite
eeBlog Home / eeBlog / Programming Pointers

Profile
Nickname: Dan Saks     Articles(35)    Visits(18339)    Comments(0)    Votes(0)    RSS
Dan Saks, a widely recognized expert in C and C++, offers tips and techniques to embedded developers.
Blog Archive:
2012 -  Apr.,  Mar
2011 -  Dec.,  Nov.,  Sep.,  Aug.,  Jun.,  May.,  Apr.,  Mar
View All
Posted: 09:23:38 PM, 13/04/2012

[Continued from Understanding virtual functions in C++ (Part 1)]

 

The is a relationship
Derivation defines an "is a" or "is a kind of" relationship between the derived and base class. That is, a circle is a shape, a rectangle is a shape, and a triangle is a shape. This relationship is only in the direction of the arrows in the diagram—from derived to base, but not from base to derived or from derived to derived. For example, a shape is not necessarily a circle, and a circle is certainly not a rectangle.


In C++, the is a relationship mani......

Vote(0)

Views(36)

View Article    Comment(0)

Posted: 11:11:46 AM, 07/04/2012

Over the past few years, I've written several articles about representing and manipulating memory-mapped devices in C and C++. Some readers commented that the C++ techniques I presented were lacking in that they failed to use more advanced features such as inheritance and virtual functions.


Classes with virtual functions can be very useful, but they aren't the solution to every problem. Classes that represent memory-mapped devices, such as the ones I've presented, work with real hardware specifically because they don't use virtual functions.


......

Vote(0)

Views(56)

View Article    Comment(0)

Posted: 06:54:09 PM, 21/03/2012

[Continued from Uses of discriminated unions (Part 1)]


A union paired with a discrete value that indicates the active member of the union is called a discriminated union or a tagged union. Some programming languages have a similar construct called a variant record. The discrete value is called a discriminator or tag. I prefer the terms discriminated union and discriminator because tag already has another meaning in C. The discriminator typically has an enumeration type, but could have an integral type.


You can write a small assortment of initialization functions to......

Vote(0)

Views(40)

View Article    Comment(0)

Posted: 11:49:10 AM, 11/03/2012

Off and on for about two years, I've been writing about techniques for representing and manipulating memory-mapped devices in C and C++. My more recent columns have been more about C++ than C, focusing on language features such as constructors and new-expressions, which C++ doesn't share with C.1, 2


Some readers have suggested that the C code I presented is preferable to the C++ code because the C structure implementations for devices are generally simpler than their corresponding C++ class implementations. Last month, I argued that the C++ implementations are actu......

Vote(0)

Views(39)

View Article    Comment(0)

Posted: 11:37:35 AM, 11/03/2012

[Continued from Writing elaborate declarations is worth the effort (Part 1)]


An extra line of defense
A few readers have observed—rightfully so—that compilers might pack or pad structure members so that the members don't overlay the device registers as expected. As I've noted in some previous columns, most of my examples used the simplifying assumption that the device registers are full four-byte (32-bit) words aligned to an address that's a multiple of four. Alignment issues aren't relevant to most of the issues I've discussed this......

Vote(0)

Views(39)

View Article    Comment(0)

Posted: 05:36:03 PM, 18/12/2011

Several months ago, I wrote an article detailing some common techniques for representing and manipulating memory-mapped devices in C.1 I followed that with another column explaining an alternative using classes in C++.2 Those initial articles left a lot of details unresolved. Most of the columns I've written since then have been about filling in those missing details.


Nearly all of the techniques I've presented are viable in that real programmers use them in real projects and find the resulting machine code to be adequately fast and compact. Nonetheless, I've......

Vote(0)

Views(115)

View Article    Comment(0)

Posted: 10:37:31 AM, 06/12/2011

[Continued from Employ member new to map devices (Part 1)]

 

The C++ Standard states that placement allocation functions are reserved, and a C++ program may not define functions that displace the versions in the Standard C++ library.8 However, a program can overload the placement allocation functions. As diligent reader willc2010 observed in an online comment, "there doesn't seem to be anything to prevent someone from defining this:
void *
operator new(std::size_t count, timer_type *p)
{
do_something;
return some_value;
}


......

Vote(0)

Views(133)

View Article    Comment(0)

Posted: 11:28:47 AM, 25/11/2011

I have previously written a number of columns detailing alternative techniques for representing and manipulating memory-mapped devices in C and C++. Due to space limitations, the initial articles left a lot of details unresolved.1,2,3 Most of the columns I've written since have focused on filling in the missing details, including a detour into constructors and automatic initialisation.4,5


Classes typically use constructors to perform object initialisation. Classes for memory-mapped devices should be no different. However, as I explained in August, many common......

Vote(0)

Views(170)

View Article    Comment(0)

Posted: 12:52:43 AM, 20/09/2011

[Continued from Learn about new with placement (Part 1)]

 

Compilers apply the usual rules for argument matching in overload resolution to find an allocation function that will accept this assembled argument list.5 The new-expression won't compile if no operator new is visible that will accept the given arguments.

 

Placement new
Bjarne Stroustrup, the designer of C++, explained that his primary motivation for extending the syntax of new-expressions was to pass information about where to place the created object.6 Hence, he dubbed the arg......

Vote(0)

Views(416)

View Article    Comment(0)

Posted: 10:28:28 PM, 07/09/2011

Classes are commonly the best tool for modeling memory-mapped devices  In C++.1 You can use a class to hide messy details, such as device register layouts and bit masks, behind a simpler and more robust interface.


A constructor is a special class member function that provides guaranteed initialization for objects of its class type.2 Using constructors to initialize objects is common practice in C++. C++ programmers should reasonably expect classes for memory-mapped devices to do initialization via constructors, unless there's some compelling reason to do othe......

Vote(0)

Views(432)

View Article    Comment(0)

 

 

CONTACT US TO OWN A BLOGNew!  

Have Your Say!

Got something to say? Why not share itwith other engineers?

CONTACT US TO OWN ONE!

SEE WHAT OTHERS HAVE SAID?

Top eeBlog Keywords

1.  book review

2.  fpga

3.  processor

4.  ipad 2

5.  ipad

Datasheets

Datasheets

Looking for parts to specify for your design project? Browse our library of datasheets NOW!

  • LT1640AH Negative Voltage Hot Swap Controller
  • LT4220 Dual Supply Hot Swap Controller
  • LT4250H Negative 48V Hot Swap Controller
  • LT4254 Positive High Voltage Hot Swap Controller with Open-Circuit Detect
  • LTC1643A PCI-Bus Hot Swap Controller

...more datasheets

Industry News

...more

eeBlogs
eeForum homepage