Skip navigation

I really couldn’t get it.

But now I do.

The problem traces back to this example, which I won’t say anything bad about, except:

MYSQL *connection, mysql;

Now I’m pretty good with C++. I really am. But I ( forgot ? whoops : did not know) that this declaration creates:

  1. A variable, static type MYSQL *, identifier ‘connection’
  2. Another variable, static type MYSQL, identifier ‘mysql’

Did you NOT just do a double take?

Let me further elaborate.

The following lines of code ARE NOT EQUIVALENT to the bolded line above

MYSQL *connection ;
MYSQL * mysql ;

Which is effectively what I did, and which is why I got the well deserved

Unhandled exception at 0x1000edb7 in MYSQL_CLIENT_2005.exe: 0xC0000005: Access violation writing location 0x000003b0.

So the declaration:

MYSQL *connection, mysql;

When broken into 2 lines is:

MYSQL *connection ;
MYSQL mysql ;

Really, I don’t like how that is. Basically the “pointer” part of the declaration sticks to the identifier, NOT to the type specifier at the front.

I thought I could make 10 int pointers like:

int * a,b,c,d,e,f,g,h,i,j ;

But it turns out you’ve have to do:

int *a, *b, *c, *d, *e, *f, *g, *h, *i, *j ;

We all learn..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: