Name: Anonymous 2010-05-24 12:37
Hi, /prog/.
What is the most beloved syntax style here? KR? BSD? GNU, perhaps?
What is the most beloved syntax style here? KR? BSD? GNU, perhaps?
int
main
(
int argc,
char **argv
)
{
const char *s;
s = "Hello world!";
printf("%s", s);
return 0;
}
#include <iostream>
using namespace std;
const char *what = "an anus";
int main( int argc, char *argv[] ) {
if( argc != 2 ) {
cout << "usage: " << argv[0] << " [text]" << endl;
return 0;
}
cout << argv[1] << " is " << what << endl;
return 0;
}
// comments inside indented blocks, /* comments */ at top level.
int give_me_dicks() {
int dicks;
if (stuff()) {
dicks = aids(); }
else {
dicks = youre_mom(); } //YHBT
return dicks; }! ! !#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes
const char *what="an anus";mainstart if(argc!=2){cout<<"usage: "<<argv[0]<<" [text]\n";return0;}cout<<argv[1]<<" is "<<what<<"\n";mainend
#include <iostream>
#include <stdlib.h>
#include <time.h>
std::string phrases[4] = {
"I personally use Notepad2 and avoid any \"makefiles\"(which i consider bloated and poor design)",
"I use one include file for everything.",
"Anything which uses makefiles is defective Sepples-level shit.",
"All the C code posts on my blog are void.h merged with somefile.c"
};
class Frozen {
public:
Frozen();
void post();
private:
std::string retarded_phrase;
};
Frozen::Frozen() {
srand( time( NULL ) );
retarded_phrase = phrases[ rand() % 4 ];
}
void Frozen::post() {
std::cout << retarded_phrase << endl;
}
int main(void) {
Frozen * progtroll = new Frozen;
progtroll->post();
delete progtroll;
return 0;
}
public: et al. to the same level as other code in a class definition is awful, because they're fundamentally different from the rest of the content. Same applies for labels and case statements. I prefer writing these lines at the indentation level of the enclosing block, but anything except what you did would be an improvement to readability.int *a, *b is consistent, but I don't like declaring a bunch of variables on one line, either, so really which way you write it doesn't matter a whole ton. Consistency and clarity do, however, so the goal is to come up with something that communicates your intent, and stick with it, whatever it might be.progtroll dynamically simply to show how you format pointer declarations, but if not, there really wasn't a reason to allocate and then deallocate one single instance of something unconditionally within the same function.srand exactly once, at the start of your program. (If you meant to have a different RNG for each instance of that class, you did it wrong.) I would also avoid the [4] in the array declaration, using [] instead. (Or does C++ disallow that for some insane reason? I'm not really a C++ programmer, I just use it when I have to)endl part of std?[a, b, c, d] or[ a
, b
, c
, d
]foo( a, b, c );
foo (a, b, c);
foo(a,b,c); /* FV-stylée */