Skip to content

Clever Code

Showcase your best code, your most elegant solution, or your most hard fought subtle bug you've found and fixed

This category can be followed from the open social web via the handle clever-code@forum.codeproject.com

361 Topics 3.2k Posts
  • Clipboard Issue

    help debugging question
    7
    0 Votes
    7 Posts
    22 Views
    R
    PJ Arends wrote: I looked at that too, but I was under the impression that UNICODE apps would automagically translate CF_TEXT to CF_UNICODETEXT. Nope. I have set up a macro that #defines another constant to be one or the other depending on whether I'm compiling for Unicode, but it's not done automatically. I can't remember about reading, but I think you still have to specify it. Remember that you can copy both to the clipboard, so both are available at any time. Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
  • Bug caused by sloppy programming [modified]

    help windows-admin debugging
    7
    0 Votes
    7 Posts
    16 Views
    R
    Might have been. It's been a long time since the bug got fixed Mike Dimmick wrote: Too few programs take advantage of this Ahem.. http://www.codeproject.com/w2k/regsvrex.asp[^] :) Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
  • A C++/CLI bug I made once :-)

    c++ csharp com help discussion
    11
    0 Votes
    11 Posts
    26 Views
    E
    :laugh: :laugh: He is Yoda^ man!! :-> --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
  • if(x=5)

    help c++ com architecture
    33
    0 Votes
    33 Posts
    76 Views
    Z
    Henize wrote: The Singularity project is going quite well. It is very interesting, check it out. When they produce an OS that is both stable and efficient enough to compete with a native OS, then I'll look more into it. As it stands right now, it is just another in a line of attempts to use "lazy languages" to do things they weren't designed for. I've seen this fail twice in the past (with both Sun and Microsoft). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
  • Bug caused by overarchitecting [modified]

    help debugging tools architecture
    3
    0 Votes
    3 Posts
    10 Views
    R
    Yes:) Pretty obvious and read that several times when reading C++ books. But yet I committed the mistake. In the actual application, the issue was far more complex and it involved network communication between processes and the problem was discovered when a different build of the dlls were on the server and the client machine. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
  • Just found one now

    help performance question
    3
    0 Votes
    3 Posts
    8 Views
    E
    Unfortunately I don't have the luxury of floats on the platform that I'm developing (mobile phone)
  • Double Bug

    help announcement
    15
    0 Votes
    15 Posts
    43 Views
    N
    Mr.Brainley wrote: Well, all this implicit copying compilers do and stuff like that, i really don't get it, so could you please explain where exactly the leak is ? A char array is new'd but there's no corresponding delete. Regards, Nish Nish’s thoughts on MFC, C++/CLI and .NET (my blog) Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog
  • Unconventional for-loop bug

    c++ regex help
    6
    0 Votes
    6 Posts
    20 Views
    Z
    Kevin McFarlane wrote: You mean they use for_each and so on? But I suspect most people learn STL initially by going through all the looping stuff. Better than avoiding it completely as many do. Algorithms and function objects I found mysterious for quite some time. I was the same way. I treated vectors like normal c-style arrays. It wasn't until my data structures and algorithms class that I learned otherwise. After the first program in that class, we were no longer allowed to write our own loops. It definitely made you think about your design a little more by doing that. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
  • A (non) hex literal

    csharp c++ com tools question
    4
    0 Votes
    4 Posts
    15 Views
    P
    may be they thought cp is a codeproject.:-O -Prakash
  • Oldies [modified]

    csharp c++ com tools question
    11
    0 Votes
    11 Posts
    25 Views
    R
    Ravi Bhavnani wrote: How about now? Much appreciated ;) Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
  • Dim MonetaryProperty As Float

    database com help
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • C# Yield issue

    csharp help asp-net com design
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • Vector and references

    help graphics debugging code-review
    6
    0 Votes
    6 Posts
    12 Views
    Z
    There is actually 2 problems. First, vector (and all the STL containers) store copies of objects. This isn't a problem unless something is done to the vector (e.g. sort it) and the object that you were referencing is now moved to another location in the vector. Thus, the memory your reference is now looking at contains different data than what you thought you were operating on. Second, if the vector has to be resized to accomidate your additions, the memory location that obj is at may no longer be allocated for that object, so you would be accessing invalid memory (or possibly accessing memory that is now allocated for something else). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
  • Or

    3
    0 Votes
    3 Posts
    9 Views
    I
    Speaking as a former mainframer, I assure you it makes perfect sense in COBOL.
  • Another fun one

    database debugging sales help
    3
    0 Votes
    3 Posts
    9 Views
    R
    Shog9 wrote: But why?! Because :) Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
  • How could I forget this

    com sysadmin testing debugging tools
    4
    0 Votes
    4 Posts
    14 Views
    S
    Rama Krishna Vavilala wrote: Since then I never try to hand optimize by not using #import. #import rocks. I would hardly ever use COM from C++ if it weren't for #import. :cool: ---- Scripts i’ve known... CPhog 1.8.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
  • 0 Votes
    1 Posts
    3 Views
    No one has replied
  • This may be an easy one to spot:

    2
    0 Votes
    2 Posts
    7 Views
    J
    What was that programmer thinking? :) -- The Show That Watches Back
  • Simple allocate and loop-through bug,

    c++ com architecture help question
    5
    0 Votes
    5 Posts
    11 Views
    R
    Chris Maunder wrote: It took me a disturbingly long time to pick that one. I spent the whole time looking for a fence-post problem. It wasn't until I googled "[LAST_YEAR+1-FIRST_YEAR][NSTATIONS]" that I found the answer :-O -- Russell Morris Morbo: "WINDMILLS DO NOT WORK THAT WAY!"
  • Subtle but Deadly ...

    c++ graphics data-structures business
    15
    0 Votes
    15 Posts
    35 Views
    J
    Yeah, but still? If the precondition was size != 0, what could you do? I do stuff like ASSERT(!"You're stupid!") to tell them like it is! :-D -- Pictures[^] from my Japan trip.