Click here to Skip to main content
15,911,890 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to open and read/write from multiple serial ports at the same time? Pin
Le@rner17-Jul-11 20:42
Le@rner17-Jul-11 20:42 
AnswerRe: How to open and read/write from multiple serial ports at the same time? Pin
Code-o-mat17-Jul-11 20:50
Code-o-mat17-Jul-11 20:50 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Le@rner17-Jul-11 20:56
Le@rner17-Jul-11 20:56 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Code-o-mat17-Jul-11 21:36
Code-o-mat17-Jul-11 21:36 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Le@rner17-Jul-11 21:38
Le@rner17-Jul-11 21:38 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Code-o-mat17-Jul-11 21:52
Code-o-mat17-Jul-11 21:52 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Le@rner17-Jul-11 22:05
Le@rner17-Jul-11 22:05 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Code-o-mat17-Jul-11 22:35
Code-o-mat17-Jul-11 22:35 
GeneralMessage Removed Pin
16-Dec-11 0:14
Le@rner16-Dec-11 0:14 
GeneralRe: How to open and read/write from multiple serial ports at the same time? Pin
Code-o-mat16-Dec-11 0:29
Code-o-mat16-Dec-11 0:29 
Questionarray declaration Pin
Danzy8317-Jul-11 10:17
Danzy8317-Jul-11 10:17 
AnswerRe: array declaration Pin
Richard Andrew x6417-Jul-11 10:47
professionalRichard Andrew x6417-Jul-11 10:47 
GeneralRe: array declaration [modified] Pin
Danzy8317-Jul-11 11:56
Danzy8317-Jul-11 11:56 
GeneralRe: array declaration Pin
Richard Andrew x6417-Jul-11 13:45
professionalRichard Andrew x6417-Jul-11 13:45 
GeneralRe: array declaration Pin
Richard MacCutchan17-Jul-11 22:59
mveRichard MacCutchan17-Jul-11 22:59 
AnswerRe: array declaration Pin
«_Superman_»17-Jul-11 15:45
professional«_Superman_»17-Jul-11 15:45 
GeneralRe: array declaration Pin
Richard Andrew x6417-Jul-11 16:14
professionalRichard Andrew x6417-Jul-11 16:14 
GeneralRe: array declaration Pin
«_Superman_»17-Jul-11 16:33
professional«_Superman_»17-Jul-11 16:33 
GeneralRe: array declaration Pin
Richard Andrew x6417-Jul-11 17:32
professionalRichard Andrew x6417-Jul-11 17:32 
GeneralRe: array declaration Pin
Richard MacCutchan17-Jul-11 23:08
mveRichard MacCutchan17-Jul-11 23:08 
GeneralRe: array declaration Pin
«_Superman_»18-Jul-11 9:10
professional«_Superman_»18-Jul-11 9:10 
Take a look at the following examples.

Say I have a function as below -
void fun(char (*p)[10])
{
    cout << *p << endl;    // Will output Hello
}
Now you will be able to call it as -
char name[10];
strcpy_c(name, "Hello");
fun(&name);
But you will get a compile error if you try something like -
char name[11];    // Wrong size
strcpy_c(name, "Hello");
fun(&name);
You could have a slightly different version using references -
void fun(char (&r)[10])
{
    cout << r << endl;    // Will output Hello
}

char name[10];
strcpy_c(name, "Hello");
fun(name);

char name2[11];    //Wrong size
strcpy_c(name2, "Hello");
fun(name2);    // Compile time error
So even though the code calling the function looks exactly like it does when using a function accepting a simple character pointer, it is a safe function.
This is exactly how the new safe string functions are implemented.
The advantage here is that you do not need to pass in a second size parameter to the function and the check for the size is done by the compiler at compile time.

But when you allocate memory using new, then it becomes something like -
char (*p)[10] = new char[5][10];
You can now pass this on to a function, but you would need another level of indirection -
void fun(char (**p)[10]){}
fun(&p);
Or
void fun(char (*&p)[10]){}
fun(p);

«_Superman 
I love work. It gives me something to do between weekends.


Microsoft MVP (Visual C++)

Polymorphism in C

GeneralRe: array declaration Pin
Richard MacCutchan18-Jul-11 9:19
mveRichard MacCutchan18-Jul-11 9:19 
QuestionControlling microphone gain using "mixer" API? Pin
Vaclav_17-Jul-11 7:40
Vaclav_17-Jul-11 7:40 
AnswerRe: Controlling microphone gain using "mixer" API? Pin
Mark Salsbery17-Jul-11 11:46
Mark Salsbery17-Jul-11 11:46 
GeneralRe: Controlling microphone gain using "mixer" API? Pin
Vaclav_17-Jul-11 12:15
Vaclav_17-Jul-11 12:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.