Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » const char *? -- more n00bisms

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
const char *? -- more n00bisms
Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

what else are commas used for in C++ besides parameter lists?

for (x=0,y=0; x<10; ++x);

Quote:

is rendered as: ... no?

It's undefined, although for any given compiler it's probably well defined.

Michael Jensen
Member #2,870
October 2002
avatar

holy shit, I knew you could do stuff like:

int x=f(), y=g();

but I didn't know you could do stuff like:

  int x, y, z;
  
  x= first(), y=second(), z=third();

and they do get called in the right order.

1#include <stdio.h>
2#include <vector>
3#include <string>
4#include <iostream>
5 
6using namespace std;
7 
8vector<string> v;
9 
10int first()
11{
12 v.push_back("first");
13 return 1;
14}
15 
16int second()
17{
18 v.push_back("second");
19 return 2;
20}
21 
22int third()
23{
24 v.push_back("third");
25 return 3;
26}
27 
28 
29int main()
30{
31 int x, y, z;
32
33 x= first(), y=second(), z=third();
34 
35 
36 for (int i=0; i<(int)v.size(); i++)
37 {
38 cout << v<i> << endl;
39 }
40 
41 return 0;
42}

ImLeftFooted
Member #3,935
October 2003
avatar

while(i = in.get(), in.good())

Theres a fun way to use commas.

Rampage
Member #3,035
December 2002
avatar

compiler said:

/tmp/http.19203.c:5: warning: left-hand operand of comma expression has no effect

I thought it would give an error, but it's just a warning. :o

-R

 1   2   3 


Go to: