C++ expression(s)
-
Today i found some really weird expression in some C++-code
if(++(k=j) != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}and just ~30 lines below that weird if statement i found this:
k = j;
if(++k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}why always so weird? Why don' to it in an nice way
k = j + 1;
if(k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}In some other code a few days ago i found this
n[idx++] = a[++idx2]++;
where both, a and n, are defined as
void*
What are the ugliest C++ expressions that have you seen in the last few weeks/months -
My favourite is the
-->
"operator".int counter = 10;
while (counter --> 0)
{
// do something
}Some people consider it ugly.
It's... wonderful. And weird.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver "When you have eliminated the JavaScript, whatever remains must be an empty page." -- Mike Hankey
-
Today i found some really weird expression in some C++-code
if(++(k=j) != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}and just ~30 lines below that weird if statement i found this:
k = j;
if(++k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}why always so weird? Why don' to it in an nice way
k = j + 1;
if(k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}In some other code a few days ago i found this
n[idx++] = a[++idx2]++;
where both, a and n, are defined as
void*
What are the ugliest C++ expressions that have you seen in the last few weeks/monthsC3D1 wrote:
k = j + 1;
That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
"I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns. -
C3D1 wrote:
k = j + 1;
That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
"I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.CDP1802 wrote:
C3D1 wrote:
k = j + 1;
That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.
I think you're mistaken. k gets assigned
j + sizeof(*j)
, notj + sizeof(*k)
. Hopefully j and k are compatible pointer types. Edit: I'm not sure whatk = j + 1
has to do with++k
. In any case, ++k does not increment by the size of the type of k, but rather by the size of the type k references. -
My favourite is the
-->
"operator".int counter = 10;
while (counter --> 0)
{
// do something
}Some people consider it ugly.
Brilliant! I actually Googled to find whether that "operator" really exists in C++! :doh:
You have just been Sharapova'd.
-
My favourite is the
-->
"operator".int counter = 10;
while (counter --> 0)
{
// do something
}Some people consider it ugly.
That's evil.
Kitty at my foot and I waAAAant to touch it...
-
Today i found some really weird expression in some C++-code
if(++(k=j) != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}and just ~30 lines below that weird if statement i found this:
k = j;
if(++k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}why always so weird? Why don' to it in an nice way
k = j + 1;
if(k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}In some other code a few days ago i found this
n[idx++] = a[++idx2]++;
where both, a and n, are defined as
void*
What are the ugliest C++ expressions that have you seen in the last few weeks/monthsVile. Implementation-dependant. X|
-
Today i found some really weird expression in some C++-code
if(++(k=j) != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}and just ~30 lines below that weird if statement i found this:
k = j;
if(++k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}why always so weird? Why don' to it in an nice way
k = j + 1;
if(k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}In some other code a few days ago i found this
n[idx++] = a[++idx2]++;
where both, a and n, are defined as
void*
What are the ugliest C++ expressions that have you seen in the last few weeks/monthsC3D1 wrote:
What are the ugliest C++ expressions that have you seen in the last few weeks/months
In no particular order[1]:
#include "stdafx.h"
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
//{{AFX_MSG_MAP(CMainFrame)//}}AFX\_MSG\_MAP ON\_COMMAND(ID\_HELP, OnHelp)
END_MESSAGE_MAP()
CMainFrame::CMainFrame()
[1] Oh who am I kidding, it's Friday and I'm just going down a file and pasting in the order found.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
My favourite is the
-->
"operator".int counter = 10;
while (counter --> 0)
{
// do something
}Some people consider it ugly.
-
C3D1 wrote:
What are the ugliest C++ expressions that have you seen in the last few weeks/months
In no particular order[1]:
#include "stdafx.h"
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
//{{AFX_MSG_MAP(CMainFrame)//}}AFX\_MSG\_MAP ON\_COMMAND(ID\_HELP, OnHelp)
END_MESSAGE_MAP()
CMainFrame::CMainFrame()
[1] Oh who am I kidding, it's Friday and I'm just going down a file and pasting in the order found.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt