on-internet

Forcing single-argument constructors to be explicit in C++

By default, in C++, a single-argument constructor can be used as an implicit conversion operator. This can be suppressed by marking the constructor as explicit. I'd prefer to make "explicit" be the default, so that the compiler cannot silently use these constructors for conversion. Is there a way to do this in standard C++? Failing that, is there a pragma (or similar) that'll work in Microsoft C++ to do this? What about g++ (we don't use it, but it might be useful information)?

Join the discussion →

If you shouldn't throw exceptions in a destructor, how do you handle errors in it?

Most people say never throw an exception out of a destructor - doing so results in undefined behavior. Stroustrup makes the point that "the vector destructor explicitly invokes the destructor for every element. This implies that if an element destructor throws, the vector destruction fails... There is really no good way to protect against exceptions thrown from destructors, so the library makes no guarantees if an element destructor throws" (from Appendix E3.2). This article seems to say otherwise - that throwing destructors are more or less okay. So my question is this - if throwing from a de

Join the discussion →

Position an element relative to its container

I'm trying to create a horizontal 100% stacked bar graph using HTML and CSS. I'd like to create the bars using DIVs with background colors and percentage widths depending on the values I want to graph. I also want to have a grid lines to mark an arbitrary position along the graph. In my experimentation, I've already gotten the bars to stack horizontally by assigning the CSS property float: left. However, I'd like to avoid that, as it really seems to mess with the layout in confusing ways. Also, the grid lines don't seem to work very well when the bars are floated. I think that CSS positioning

Join the discussion →

PHP DOMDocument stripping HTML tags

I'm working on a small templating engine, and I'm using DOMDocument to parse the pages. My test page so far looks like this: <block name="content"> <?php echo 'this is some rendered PHP! <br />' ?> <p>Main column of <span>content</span></p> </block> And part of my class looks like this: private function parse($tag, $attr = 'name') { $strict = 0; /*** the array to return ***/ $out = array(); if($this->totalBlocks() > 0) { /*** a new dom object ***/ $dom = new domDocument; /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** load the html into the object ***/ if($strict==1) { $do

Join the discussion →

Displaying build times in Visual Studio

Our build server is taking too long to build one of our C++ projects. It uses Visual Studio 2008, running devenv.com MyApp.sln /Build -- see devenv command-line switches (although that's for a newer version of VS). Is there a way to get devenv.com to log the time taken to build each project in the solution, so that I know where to focus my efforts? Improved hardware is not an option in this case. I've tried setting the output verbosity (under menu Tools → Options → Projects and Solutions → Build and Run → MSBuild project build output verbosity). This doesn't seem to have any effect in the IDE.

Join the discussion →

Deleting a buffer through a different type of pointer

Say I have the following C++ code: char *p = new char[cb]; SOME_STRUCT *pSS = (SOME_STRUCT *) p; delete pSS; Is this safe according to the C++ standard? Do I need to cast back to a char* and then use delete[]? I know it'll work in most C++ compilers, because it's plain-ordinary-data, without any destructors. Is it guaranteed to be safe?

Join the discussion →

Is it worth encrypting email addresses in the database?

I'm already using salted hashing to store passwords in my database, which means that I should be immune to rainbow table attacks. I had a thought, though: what if someone does get hold of my database? It contains the users' email addresses. I can't really hash these, because I'll be using them to send notification emails, etc.. Should I encrypt them?

Join the discussion →

Using bitwise operators for Booleans in C++

Is there any reason not to use the bitwise operators &, |, and ^ for "bool" values in C++? I sometimes run into situations where I want exactly one of two conditions to be true (XOR), so I just throw the ^ operator into a conditional expression. I also sometimes want all parts of a condition to be evaluated whether the result is true or not (rather than short-circuiting), so I use & and |. I also need to accumulate Boolean values sometimes, and &= and |= can be quite useful. I've gotten a few raised eyebrows when doing this, but the code is still meaningful and cleaner than it would be otherwi

Join the discussion →

What's the purpose (if any) of "javascript:" in event handler attributes?

I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the javascript: prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there any appreciable difference between: onchange="javascript: myFunction(this)" and onchange="myFunction(this)" ?

Join the discussion →

Keep Remote Directory Up-to-date

I absolutely love the Keep Remote Directory Up-to-date feature in Winscp. Unfortunately, I can't find anything as simple to use in OS X or Linux. I know the same thing can theoretically be accomplished using changedfiles or rsync, but I've always found the tutorials for both tools to be lacking and/or contradictory. I basically just need a tool that works in OSX or Linux and keeps a remote directory in sync (mirrored) with a local directory while I make changes to the local directory. Update Looking through the solutions, I see a couple which solve the general problem of keeping a remote direc

Join the discussion →