- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
You are probably running that control logic on a secondary thread, and that thread forces the whole process to exit when it decides it's time to blow-up...
Admin
Anyone who has been in the industry significantly long knows the power of code inertia. If code is fubar, the maintainers are more likely to endure it than take any radical steps to fix it, mainly because of QA and time to market concerns. Today I have no trouble reading misindented C code because for four years that's what I maintained.
The professional thing to do when you need to use an unfamiliar language is to learn it. Someone who needs these macros to use C effectively doesn't belong in a C programming job. It's that simple.
Admin
why stop there?
#define forever while(1)
#define untilbreak forever
#define untilreturn untilbreak
Admin
You can't be serious on this...
If you we're working for me I would have fired you at once.
In such a case you should code:
if ( x != y )
printf( "X and Y are not equal!\n" );
which actually relates to the condition you are looking for...
Admin
Well just suppose that this is ot 500K lines of C++ code.. And I guess it is not... From CLISP's CodingStyle
Admin
ResourceWrapper r(allocateResource());
do_stuff(r);
Admin
On the one hand, a lot of beginning C programmers coming from a Pascal or FORTRAN background are tempted to do this, because it looks more familiar and seems less inscrutable than all those braces. I'll admit to having written a header like this at first myself. The difference is, most quickly realize that it just makes things more confusing, not less, and it rarely goes beyond the first program done that way.
OTOH, to see this in production code is really, really quite sad. Apparently, someone took the aphorism about writing FORTRAN in any language a bit too literally.
As for syntax hacking... there are some languages which can reasonably accomodate that. C isn't one of them.
Admin
Once upon a time, there was B. And it was good. But nobody ever heard of B, so we'll skip to the next chapter. After all, we've aready skipped COBOL, Fortran, and APL.
Once upon a time, there was C. And programmers saw that it was very good. Indeed, its devotees considered it perfect.
And the Standard Template Library grew and was refined. And people forgot what the C Language was as distinct from the STL, but that mattered not since C was perfection.
And the Pascal compiler companies moved to California to get rich off of news services. (Well, Alice moved there, anyway.) And C grew in its influence.
And lo, compiler groups said they could not improve on perfection, so they developed C++. And Micro$oft released VisualBasic. And lo, Tcl and Tk burst forth. (No, Tcl and Tk didn't break "Forth".) And Perl ventured out into the wild. And Python followed suit. Some were awakened with Java. But PHP wasn't considered a language, so it was widely used. Ruby on Rails followed Ruby. Others were busy since the beforetimes with SmallTalk, some with a LISP. And lo, C was perfect without any need to change.
Yeah. C is the first letter in Crap.
Hey, if the guy had written this using REs and SQL queries, generating p-code, he'd be onto something. He'd be on the wrong side of the compiler executable, but he'd be onto something. As it is, he's just personalizing the language (call it "C-me"), as others have done before and as others will do again.
Admin
Save your personalized languages for your personal projects, please.
Admin
To begin with the STL is part of the C++ standard, not C. Then you seems to blame that C or C++ never change when they are ! The last C revision is from 1999 and the next C++ standard is expected around 2009. The thing is that C/C++ are ISO (and ANSI) so changes are done like any ISO thing, slowly and carefully (and probably with too much considerations for backward compatibility). Comparing how fast/often it updates with any languages that are not in the same category is just retarded too.
p.s: C++ was developped by "he" not "they"
Admin
I forgot to add C/C++ are far from perfection, like any languages.
Admin
Hasn't anyone heard of Cobol?
Admin
s/Standard Template Library/Standard C Library/g
s/STL/SCL/g
Because, apparently, my point was incomprehensible with that error. And some still won't get it.
Admin
yeh man whats the big deal
what do we need standards for, anyway?
i invented my own version of UML the other day, i call it NSUML (not so universal markup language) sure it'll be a small nuisance, but i think you can understand it if you take a few minutes to familiarize yourself with it:
[*]----[st]----[co]
|
|
[B]
Admin
Please say this is a dream...
Admin
I quit my first job because the non-Cobol project I was promised a position on was run without me, after 15 months programming Cobol I knew I either had to quit, go crazy, or both.
I quit, whether I went crazy I'll leave for others to decide [:P]
Admin
This kind of preprocessor-based, poor man's syntactic sugar is quite commonplace in embedded systems source code (e.g. see http://www.bytecraft.com/tidbits.html).
I use a few header files containing this kind of stuff, both to avoid falling in traps and to ease code review :
// reset
#define BITS__RST(variable, bits) ((variable) &= ~(bits))
// set
#define BITS__SET(variable, bits) ((variable) |= (bits))
or
#define ITEMS_IN_ARRAY(array) (sizeof(array) / sizeof(*(array)))
Admin
I agree with that, perhaps he came from having started out with a different
language or something - I now when I started C I used EQ to represent '=='
just so I wouldn't make the mistake of using '=' in during comparisons.
Dr MindHacker
Admin
What language is that? Because it damn well isn't C, where sizeof(array) returns the size of the POINTER to the first element of the array, which will always be the same regardless of how many items the array holds.
Admin
No, it's correct if you pass an array on the stack to it (and not a pointer you received via some function).
Admin
Hmm, I think, you're mistaken. This program
give the following output: 40 4 10...
Admin
> What language is that? Because it damn well isn't C, where sizeof(array) returns the size of the POINTER to the first element of the array, which will always be the same regardless of how many items the array holds.
POINTER what? We are talking about arrays here.
Admin
Before ISO 8859-1 got common, ÅÄÖåäöÜü was equivalent to []}{|^~ in the ASCII variant used in Sweden, and you could see code like this:
f() ä
aÅ0Ä="abcÖn";
å
and we were fluent in reading and writing plain text with brackets: g|kst|vlar g}sb{gare m|tesb}tar sn| b}t l|k
depending on how the terminal emulator was configured
Admin
Hey guys I found a great website which I think could be useful for your new missile project
http://en.wikipedia.org/wiki/Halting_problem
Admin
My favourite like this is to go
#define the_cows_come_home 0
so that you can go
do { ... } until ( the_cows_come_home );
Admin
Are you being serious?
Admin
I think he is, what's wrong in what he said ?
int arr[20]; sizeof(arr); // correct, gets sizeof(int(*)[20])
int arr[20]; int* p = arr; sizeof(p); // incorrect, gets sizeof(int*)
Admin
sizeof is one of the few contexts where the type of the array identifier does not automatically decay to a pointer; sizeof will return the total number of bytes used by that array, so provided that the macro argument is really of an array type, the expression above will return the right value.
Admin
Creating a do_nothing macro or procedure is actually useful for debugging; it allows you to place a breakpoint inside an otherwise empty "else" clause.
Admin
> Are you being serious?
Of course.
Arrays and pointers are two (very) different beasts; read this part of the C FAQ for more information : http://c-faq.com/aryptr/index.html (a very interesting part indeed, because many people do not actually understand this part of the sometimes weird semantics of C).
Admin
The difference is that when you sit down to work on a haskell program, you expect that behavior. When you sit down to work on C program, you don't, so when it happens, it's annoying.
Also, I wonder why there aren't many enterprise type apps written in Haskell? hhmmm...
Admin
People always get arrays and pointers confused, but most especially when you consider it in terms of the sizeof() operation. What people really don't understand is that while sizeof() looks like a function, and acts like a function, it's actually evaluated at compile time. So if you did something like this:
void main()
{
int array[5];
printf("%d ",sizeof(array));
myfunc(array);
}
void myfunc(int * array)
{
printf("%d ",sizeof(array));
}
What you get will be 20 followed by 4 (assuming 32-bit ints and pointers). In main, "array" is an array of 5 ints, which is 20 bytes long. In myfunc(), it's still the same array, but you're not printing the size of it, you're printing the size of a pointer to it. sizeof() is evaluated at compile time to 20 and 4, respectively.
Admin
sigh
In C, arrays are syntactic sugar for pointer manipulation.
a[3] is actually something like *(a + 3)
Admin
I just noticed your other posts, so it seems that you are in fact, aware of this.
There's no promise that the array in question will, in fact, be treated as an array in sizeof().
Mostly, it will only be treated as an array if it is a local. Otherwise, it will decay to a pointer.
Admin
Because most people don't have the ability to understand functional programming, or find it too difficult to learn, or just don't want to learn FP.
Oh, and FP does not have giant corporations behind it, FP doesn't "feel natural" unless you have a heavy math backround, when programmers have a hard time grokking FP there's no way in hell most managers could even begin to understand it, ...>/p>
Admin
Yes. They're easy to identify. They use C by choice.
Admin
Except real cruise-missile software requires a level of reliability that is too expensive to achieve in C, so it's written in Ada.
Admin
Hmmm ... being paid to write code whose intent is to crash the system ... *into* other things ... cool ...
Admin
#define BEGIN {
#define END }
is not enough!!
It should be:
#define begin {
#define begiN {
#define begIn {
#define begIN {
#define beGin {
#define beGiN {
#define beGIn {
#define beGIN {
#define bEgin {
// ... and so on...
#define BEGIN {
Admin
Probably because it is kind of like the chicken/egg paradox: few people use Haskell (or Eiffel, or Scheme, or any other good-but-otherwise-confidential-in-the-industry language) because... few people use it, so few good tools and libraries are available.
As harsh as it sounds, it is much less risky for a development team to have to deal with funky run-time errors / prehistoric programming languages than with potential platform obsolescence*.
* not in the technical meaning of the term.
Admin
Great idea, I've already started writing all my programs in this new XML based language, I like to call it 'Better XML'
<?xml version="1.0" encoding="iso-8859-1"?>
<Better_XML>
<variable type="boolean" name="is_xml" value="true"/>
<if>
<expression>
<call type="function">isTrue
<arguement name="is_xml"/>
</call>
</expression>
<statements>
<print>WTF!</print>
<exit/>
</statements>
</if>
<function name="isTrue">
<parameter type="boolean" name="value_to_check"/>
<if>
<expression>
<call type="function">isTrue
<arguement name="value_to_check"/>
</call>
</expression>
<statements>
<return>true</return>
</statements>
</if>
<else>
<statements>
<retur>false</return>
</statements>
</else>
</function>
</Better_XML>
Admin
If the sizeof operand has an array type in the current scope, then it does not decay to a pointer. You're thinking of passing an array as an argument to a function and then using that argument as the sizeof operand, in which case the decay happened as part of the function call, and the sizeof operand is already of pointer type.
Admin
Sorry, I think I misuderstood the entire post. The way I read it, it looked like someone had posted something that implied
int *p = new int[20];
sizeof(p); // returns sizeof(int)
(which is correct)
and that Anonymous was claiming that sizeof(p) would return sizeof(int) * 20, which is obviously wrong.
It would appear I misread the whole thread. Sorry about that.
Admin
No, sizeof(p) returns sizeof(int*). Now the size of any pointer has the same size than an int on most x86 implementations.
Admin
Seems this guy was trying to fix some of the obvious flaws of C, everyone should take note.
Admin
Wow, I'm impressed that my little comment garnered so much attention and stirred such controversy.
I was going to respond, but most of my points have already been made. The only thing I'd add is that I have maintained <BUZZWORD>enterprise-level</BUZZWORD> code, and would agree this wouldn't be particularly advisable for it, though I still think a coder should be able to adapt to it fairly easily. Also, we don't actually know whether this application is <BUZZWORD>enterprise-level</BUZZWORD>, as there's no mention made of it.
Admin
OMG!
I wonder how old this guy is!
The repeat, unless, until, combined with GT, GE, LT... it looks like BCPL.
BCPL is an old non-typed language.
Non-typed doesn't mean dynamically typed.
It means that there is no type check (a bit like assembly).
The only type is a word. And, a word could be dereferenced, or used as a function pointer, or as a vector (pointer to array), or as an integer, or as a boolean, or as a label of a goto.
I wonder if there were:
#define rv *
#define lv &
#define let union {void* p; int i;}
Admin
I was reminded of RatFor, a "Rational Fortran" language devised by Kernighan and Plauger in about 1975. This used a preprocessor to provide "modern control-flow statements" to FORTRAN (if -else, for, break, repeat until ). FORTRAN was then the most widely available "standard" language. What must FORTRAN programmers have thought?
And then, not content with tinkering with FORTRAN, Kernighan went on to devise a conpletely new language...
Admin
That's what I meant. Typo. I'm making myself look totally incompetent now... ooops.
Admin
There's a fine line between constructive criticism and plain trolling...