What does * mean?

Just a quick question.

Could someone please explain to me what the * symbol means when programming? Can't seem to find any answers with a Google search.
An example would be:

(byte *address)

or

*char

or

uint32_t (_millis)(),Serial _debug)
:telitPort(_telit),millis(_millis),DebugPort(_debug)
,fullData(NULL),parsedData(NULL)

Anyways, hope someone can help.

The * symbol has multiple meanings. In the case you cite, though, it means that the variable is a pointer. Google "C pointer" for all you ever wanted to know, and a whole lot more.

Thanks Paul!

I knew that couldn't be for multiplication!
So in the example below and on the last post is & also a pointer?

gsmGPRS myGsmGPRS(Serial3,&millis,&Serial);

So in the example below and on the last post is & also a pointer?

No. The & operator defines a reference. The value is passed by reference, not by value (which is the default in C). When passed by value, the value can be changed by the function, but any changes are unknown to the caller. When passed by reference, the address of the variable is passed to the function, so changes are persisted after the function ends.

Pass by reference is usually needed for complex objects, like Serial, because pass by value takes too much space (to copy the object) and requires extra code.

So in the example below and on the last post is & also a pointer?

gsmGPRS myGsmGPRS(Serial3,&millis,&Serial);

You can also read the symbol & as "the (memory) address of". You basically pass the address of the object in the above example.

Ok I'm starting to get an understanding of how this all works.

  • &variable = the memory address of that variable.

-int *ptr; //creates a "pointer variable" that sets aside enough bytes to store the address of an integer

-ptr = &variable; // means ptr is now pointed to the address of variable

-ptr* = 7; //means the variable at the address ptr points to is now equal to 7, therefore variable=7

Does that sound about right?
Also another quick question:
In the example below the & operator appears to be part of Serial (e.g. 'Serial&') as opposed to part of telit (e.g. &telit).
Does this mean something different, or could this same line of code be written like this: gsmGPRS::gsmGPRS(Serial &telit, ......ect..
Or maybe I'm way off and in this case the & operator is actually being used for a bitwise operation between Serial and telit?

gsmGPRS::gsmGPRS(Serial& telit, uint32_t(millis)(), Serial debug):

In the example below the & operator appears to be part of Serial (e.g. 'Serial&') as opposed to part of telit (e.g. &telit).

It makes no difference if the & (or *) is with the variable or with the type. The result is the same.

Some people like
type *var;
to clearly indicate that the variable is a pointer.

Others prefer
type* var;
to indicate that the type is "pointer of type".

The problem with declarations of the form "type* var", that whilst you can write "type* ptr0, ptr1;" only "ptr0" is a pointer, but "ptr1" is simply a variable of type "type".

The compiler will point out the error of your ways when you try to use "ptr1" as a pointer, but it can lead to confusion.

The problem with declarations of the form "type* var", that whilst you can write "type* ptr0, ptr1;" only "ptr0" is a pointer, but "ptr1" is simply a variable of type "type".

Yep. That's why I never use that form.

Ok so some more questions (if you don't mind :~)

First maybe I should explain what I'm doing. I am going through a library created for a gsm module that uses a differnt gsm chip than the module the I am using (SIM900). I would like to go through one of the examples in this library line for line, and try and understand what it is doing, with the hope that I will be able to either modify it to use commands that the SIM900 understands, or to just create my own library.

With that being said I start off with this line in the example that creates an object of type gsmGPRS called myGsmGPRS:
gsmGPRS  myGsmGPRS(Serial1,&millis,&Serial);

Next I open up the gmsGPRS library to see what that object does:

gsmGPRS::gsmGPRS(Serial& telit, uint32_t(*millis)(), Serial* debug):
GSMbase(telit, millis, debug), getData(NULL)
{
	memset(ipAddress1,'\0',IPsize);
	memset(ipAddress2,'\0',IPsize);
}

So using the inputs given in the example this is basically:
//gsmGPRS::gsmGPRS(Address of Serial1 named: telit, a millis function pointer, A pointer named debug of Serial type that points to the address of Serial):

This is where I get confused, because after the 3 inputs there is a ':' and another function (GSMbase) which is in another library as seen in the code below

GSMbase::GSMbase(Serial& _telit ,
uint32_t (*_millis)(),Serial* _debug) 
:telitPort(_telit),millis(_millis),DebugPort(_debug)
,fullData(NULL),parsedData(NULL)
{}

I assume that all of this simple makes telitPort = Serial1 (my port used to communicate between the arduino and GSM module)
Is that right?

Is that right?

Yes.

This is where I get confused, because after the 3 inputs there is a ':' and another function (GSMbase) which is in another library as seen in the code below

The constructor for the derived class, gsmGPRS, is invoking the constructor for the base class (the one that it derives from), GSMbase, passing along the stuff that was passed to it.

Thanks again, you are really helping me along with this! :slight_smile:
So, to clarify.
In the last 3 lines of the gsmBase library code I see this:

:telitPort(_telit),millis(_millis),DebugPort(_debug)
,fullData(NULL),parsedData(NULL)
{}

Does that mean that the constructor for the derived class, gsmBase, is invoking a constructor for telitPort class, millis class, DebugPort class, fullData class, and parsedData class? Also it appears those classes are declared in that same statement?

Sorry if that is a dumb question, I'm just not sure if you can invoke multiple classes just separating each one with a comma...

Does that mean that the constructor for the derived class, gsmBase, is invoking a constructor for telitPort class, millis class, DebugPort class, fullData class, and parsedData class? Also it appears those classes are declared in that same statement?

No. It is one way that values are assigned to members. The "telitPort(_telit)" bit is equivalent to "telitPort = _telit;" inside the {} for the constructor implementation.