« first day (1487 days earlier)      last day (1648 days later) » 

user10957435
2:27 AM
@JL2210 @CodyGray or @NathanOliver-ReinstateMonica would probably know if there are any quick ways to do this.
 
6:50 AM
@JL2210 That's rather non-standard syntax in C, too... Why in the world would you want to try and do this in a single line?
Write it: size_t temp = 123; foo(&temp);
That works for both C and C++.
The real "more C++ way to do it" would be not to pass a pointer in the first place. And very likely to reconsider the higher-level design so you didn't need to do this at all.
@Kyll Nope. For fun, try outputting the value of the expression sizeof('a') (which returns the compile-time size, in bytes, of the operand; in this case, a character literal).
Character literals are of type int in C, whereas they are of type char in C++, so the sizes will be vastly different (generally 4 and 1, respectively, on common architectures).
Best to think of C and C++ as merely having similar syntax, much like C++ and Java do. They're curly-brace languages, but that's about where the similarities end. What they have in common is largely the superficial. That makes it all the more confusing, of course, because, as with C++ and Java, you can often get away with writing C code in C++, and it'll "work".
 
 
2 hours later…
8:35 AM
Hah, I see
Thanks for the info
 
9:29 AM
Ah, yes, and like Java and Javascript ;))
 
 
2 hours later…
11:34 AM
@CodyGray No, that's standard C... It's called a compound literal. I don't remember why I wanted to use it anymore, though.
 
 
7 hours later…
6:15 PM
@JL2210 Yeah, it's standard in the sense that it's allowed by the standard, but I would consider it to be questionable style. Probably a poor choice of words. Your original question was how to pass a pointer, but then you declared an array consisting of one element. That's...not the same as a pointer.
 
 
2 hours later…
8:06 PM
 

« first day (1487 days earlier)      last day (1648 days later) »