« first day (535 days earlier)      last day (3079 days later) » 

6:33 AM
9
A: Are pointers considered a method of calling by reference in C?

Harisyou cannot pass by reference in C but can use pointers as an alternative Yup, thats correct. To elaborate a little more. Whatever you pass as an argument to c functions, it is passed by values only. Whether it be a variable's value or the variable address. What makes the difference is what y...

any suggestions to improve
??
 
6:47 AM
@Haris Morning
I think it's a bit problematic, because we're dealing with terminology
 
@DrorK. Ok can you be a little more specific
 
@Haris int *p; ... what is 'p'? what is 'int'?
(this is not a trick question)
@Haris 'p' is a pointer to int, and 'int' is the referenced type
Would you object to this 'reference' terminology?
 
It sounds right
 
When we do: *p ... how would you describe it?
int i; int *p = &i; *p = 123;
How would you describe: *p = 123;
Would you agree with the terminology of: p's value is a reference to i?
If so, then would it be really that different to say the same when we pass it to a function as an argument?
 
If you say it that way, then may be. But the point is that when we are talking about function calls, what we see is if the value is being passed. That value can be a reference. But in the basic sense only the value is being sent.
 
6:58 AM
Hence why I mentioned it's a matter of terminology
 
When you send a constant through the function. Something like foo(10, 20); Its not called pass by constant. in the base, it is sent as value only
@DrorK. Yes, i agree
I agree, if we see the way it works, it can be called pass-by-reference. But then what would we call the C++ example? Because it is sending the reference implicitly.
 
That's the problem, when we're dealing with C we can't consider other language's definitions/terminology
C's 'object' definition, is the same as C++?
 
@DrorK. Hmm, but isn't this a computer science concept, which has to be general for almost every language?
 
I wouldn't know what's considered to be a CS concept, when we're discussing a specific feature/property of a language the only authority is its standard's committy
Is there a general definition for 'object' which suites both C and C++, and other languages?
void func(int *p); int i; int *p = &i; func(p); ... the mechanism which is being used for passing 'p' is by-assignment, and its value is a reference to i
 
@DrorK. A concept, i would say is something that can be explained without any reference to any language
 
7:09 AM
I wouldn't know how to explain it without context
Usually when something is being explained without context, we use examples of how common implementations behave/approach it
 
@DrorK. I guess then, that there are 2 ways to look at it. If we consider what is being sent in the function call, then it can be called pass-by-reference. And if we consider how it is being sent to the function, then its always pass-by-value in C
@DrorK. May be.. I suppose examples are needed..
 
It's a matter of terminology, I don't think there's a right or wrong
 
@DrorK. Agreed :)
 
How about multi-dimensional arrays, would you consider: char array[10][10]; to be multi-dimensional?
Some people say it's not, because C doesn't have multi-dimensional arrays as other languages have
 
@DrorK. I guess the problem starts when you start comparing with languages that have implemented things differently.
@DrorK. which 'other' language?
I've to goto lunch. The hostel stops serving after a fixed timing. ;)
 
7:17 AM
@Haris Pascal? Ada?
 
 
6 hours later…
1:43 PM
Hello all
 
 
4 hours later…
user4651282
5:14 PM
helloc @fahdijbeli;
 
5:43 PM
some extra info on endiannes as an extension to the link I shared yesterday (the lost art of struct packing)
though this makes it quite hard to change struct definitions on compile time:
8
Q: Detecting Endianess

CyanI'm currently trying to create a C source code which properly handles I/O whatever the endianess of the target system. I've selected "little endian" as my I/O convention, which means that, for big endian CPU, i need to convert data while writing or reading. Conversion is not the issue. The prob...

 
Generally any consideration for implementation-details is not the easy way out
Of course when it comes to optimizations/efficiency, that's a given. But obviously most of the people who make such suggestions don't even bother with profiling/benchmarking, so that's obviously not the case for most
The discussion within Matteo's answer is pretty much 'incorrect'
 
@DrorK. not to mention that it is not even a real answer to the OP's question, as it is not compile time checking
IMO the best thing one can do, is to provide the option to choose from endiannes (#ifdef BIG_ENDIAN ...) and push this responsibility to the user who will compile one's code, that is, s/he must pass the -DBIG_ENDIAN flag to the compiler if s/he has a big endian machine
 
6:22 PM
That approach makes assumptions about implementation-details
Unless it's absolutely crucial for the nature of the program, with respect to efficiency/performance, that shouldn't be needed
 
helloc();
 
6:40 PM
@DrorK. evening
 
@DrorK. it is indeed, when you are working with 1) bit fields 2) bit flag arguments stored in bit fields
 
@PeterVaro Bit fields and almost all other types share the same property when it comes to the C standard, being an implementation-detail
Assumptions made about the representation of bit fields is the same as assumptions made about other types, it's not guaranteed
 
7:10 PM
@DrorK. ofc, that's why I suggested what I did above: push the responsibility of the decision to the user
I can implement bit fields in both ways: as little and big endians
the one will be used is based on hwo the user is compiling my code
that's all what I've said, nothing less, nothing more
 
7:32 PM
@PeterVaro You specified working with 'bit fields' as an exception, where it's not the case
The general principle applies to all types just the same, if it's not a crucial efficiency concern, being generic is probably the best way to go. The idea of dealing/querying/depending on an input for properties regards representations tastes really bad- as long as there's no crucial/significant performance consideration
Is there such a concern?
 
7:58 PM
oh there is! you see, I've shared the post right after struct packing -- which is all about micro optimizations
do we need that? not all the time, as a matter of fact most of the time we don't
but if it is 1) a real-time, high performance application (like most of the complex graphics systems are) or 2) a software running on a limited hardware -- then these tricks are awesome, and the best part is: C has all these tricks up its sleeves
if you have the "luxury" to not care about these micro-optimizations, then I would also suggest to use generic things, as they are more reliable and portable
(just as I won't recommend using C in the first place, if you have the "luxury" of not needed to be as fast as possible)
 
8:20 PM
Well sure, if there is such a concern, then implementation-details are required for fine-tuning
 

« first day (535 days earlier)      last day (3079 days later) »