difference between "using" and "#define" #10
-
@hsaturn Can you explain the difference between these lines of code: reference lines of code here
I have looked it up but I am used to code like For the Portenta neither one works, both give a hard fault. Wondering if it is an issue with how the MBED WiFiClient is written. The error is:
Which typically would be for messing with a linked list inside a "for" loop or the equivalent. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi Jeremy (Lost my answer GRRRR) #define is just a preprocessing string replacement (not seen by the compiler) using is a type alias interpreted by the compiler (not the preprocessor) An example where using cannot be used : https://onlinegdb.com/MzKsCVN5p An example where #define produces bad things https://www.onlinegdb.com/Mo5xRNL0G #define replaces the string in ANY context (except inside strings), while USING uses the alias only within type context. A last example showing why using is better when used for types https://onlinegdb.com/drGp8aWKc using TcpClient = WiFiClient; // ==> Tells the compiler to use WifiClient as real class when TcpClient is encountered.
|
Beta Was this translation helpful? Give feedback.
-
Hi Jeremy I really cannot figure out why you are giving me many "JAVA" Exceptions stacks. TinyMqtt is a C++ library, nothing related to Java. I guess that these error are related to your IDE. |
Beta Was this translation helpful? Give feedback.
Hi Jeremy (Lost my answer GRRRR)
#define is just a preprocessing string replacement (not seen by the compiler)
using is a type alias interpreted by the compiler (not the preprocessor)
An example where using cannot be used : https://onlinegdb.com/MzKsCVN5p
An example where #define produces bad things https://www.onlinegdb.com/Mo5xRNL0G
#define replaces the string in ANY context (except inside strings), while USING uses the alias only within type context.
A last example showing why using is better when used for types https://onlinegdb.com/drGp8aWKc
using TcpClient = WiFiClient; // ==> Tells the compiler to use WifiClient as real class when TcpClient is encountered.
using namespace mbed;
Is …