« first day (495 days earlier)      last day (2358 days later) » 

1:04 AM
how does one go about writing functions that return arrays in c, like in java?
 
return a pointer to the first element
and remembering how many elements are in the array
 
Use arrays like Java arrays to start with :\
 
@thecoshman what do you mean
@Telkitty what are good practices on how to go about remembering how many elements are in the array?
when you are building the array in the body of some function, suppose you do not know what the length of the array is going to be until you are ready to return. isn't that, like in java, an issue, since you need to know the size of the array you're initializing?
 
not sure whether it's a good practice but you can set a global variable or you can return struct with a pointer pointing to the start of the array and number of elements or you can set special characters to show it's the end of the array
 
Java's arrays are more than just the raw array, they have 'size' tracked. It's more like they return an object like { int size; type* data }
C arrays are very easily confused with just a pointer to the first element
 
1:10 AM
Yeah, that's pretty interesting
 
If you are using C++, don't try to return an array, use a std::vector
 
okay sweet that is what i did
there was a question in recent that had a pretty confusing description, but once I deciphered it I thought the problem would be a fun exercise just as something easy to do while trying to learn how to use CLion
 
A common pattern in C is for functions to take a pair of 'out parameters'. So the function caller passes in a pre-allocated array that can hold plenty of items and another pointer for the actually used size. This let's the function write data into the pre-allocated array and then also set how many items it actually put into that array
needles to say, it's terrible because it's going to cause problems
 
if you could look at my answer and give feedback on my c++ code that would be cool
like i said, terribly worded question
-3
Q: Program doesn't repeat (C program)

butterflyflyawaySo this is a program that the user enters the number of the digits of the number group and then the power and it is supposed to show the number that the sum of their digits on that power does the number. For some reason the program won't repeat and will only show one number or even nothing. How c...

 
basically, unless you are having to write it your self, always use something that abstracts raw arrays
something that can handle actually safely allocating memory, that releases it, that can at least warn when you attempt to access out of bounds
 
1:15 AM
yeah definitely, I believe in that. Arrays give better performance, right? but it's painful to not just use lists
The problem she is trying to solve in that question is really "Given two integers, k and n, return all numbers x such that sum(d^n) = x, where k is the number of digits in x, and we are summing over the digits d in x."
 
You are confusing things here
C++ has raw arrays T[] and then std::vector<T>. Yes, raw arrays can potentially be more performant, but vectors (which actually use arrays behind the scenes) are going to save you so many headaches for almost no overhead
 
std::array
 
what is the difference between std::vector and std::array
 
C++'s vector is not a linked list
 
yeah @thecoshman I see what you're saying. the list comparison was not appropriate
 
1:21 AM
Java has both array list and linked list that offer array like interfaces
 
I do, however, use ArrayLists in java over arrays most of the time when the arraylist size is known by me to be small
 
Why not use ArrayLists?
 
i have no reason why not to
 
I always just use them (if they do what I need) until profiling shows it's an issue
 
so just now when i was toying around, i wasn't sure how to iterate through a pointer that points to an array in cpp
 
1:25 AM
Just like you would iterate through an array normally :\
just you need to dereference all access to the array
 
this is what i think of when i think to do what you are saying
int * a = new int[] {1,2,3};

for(int &it : a){
std::cout << ' ' << it;
}
but that is not ok
and i assume this is where i need to know the length
and do a for(int i = 0; i < length; i++) loop (which i would hate to have to do in this case)
 
44 messages moved from Lounge<C++>
Don't use new
std::vector is superior
wait, you initially said "C", but you're using C++
 
I figured arrays would be the same
i meant c++ in any case
 
That said, just as in Java you would use ArrayList<T> unless you must use an array, here, you use an std::vector<T> or std::array<T, N> unless you must use an array
it helps that the number of cases where you must use an array is way, way lower than in Java
With std::vector, returning is done just like you would return any other type
 
1:43 AM
okay cool, good to know
 
 
9 hours later…
10:18 AM
Hm i will asked that again. In my appl. the user has the possibility to create new 3d objetcs. While i have only a certain amount of id's in every level of my scene graph my approach is to limit the child nodes a parent can hold. So i avoid this conflict.
 
 
1 hour later…
nwp
11:47 AM
@FerencRozsa What is the question?
 
 
1 hour later…
1:15 PM
:-) the approach. an other is to create a amount of (3d objects) nodes that not actual is part of the scene graph. the user can add each of them at runtime. when all added the user has to delete a object from the scene to add a new one.
 
nwp
The question is if giving users a hard limit on the number of objects they can use is a reasonable design decision?
 
yes nwp...its a decision i have to made to provide this functionality
 
 
4 hours later…
5:44 PM
@sehe I'm in despair
I've written fn = "TCFN" >> lit('(') >> list<Iterator, tkind_parser<Iterator>> >> ',' >> start >> lit(')');
And Qi somehow deduces that this expression produces an attribute vector<...>, which is the attribute type of the list<...>-grammar (a variable template), but the compound thing should be a pair, right
It must treat start's attribute as ignored, but why?
 
5:58 PM
I figured it out, nvm
Apparently the types have to match up...
 
 
1 hour later…
7:09 PM
@sehe How can I have a grammar/rule have a pair<> attribute instead of an implicit fusion vector?
 
7:21 PM
@Columbo huh - that makes no sense
 
@sehe why?
 
@Columbo it's... a template expression with a naked type?
@Columbo #include <boost/fusion/adapted/std_pair.hpp>
 
@sehe Variable template
 
later
 
@sehe No, I figured it out--it's compatible with std::tuple, but not std::pair!
 
7:22 PM
@Columbo how on earth should I have guess.
 
Which is really odd.
@sehe It says right there
 
SSCCE or GTFO (to quote someone else) :)
 
> And Qi somehow deduces that this expression produces an attribute vector<...>, which is the attribute type of the list<...>-grammar (a variable template)
 
code before proze
 
Sure, once I'm stuck again, I'll boil it down
 
 
4 hours later…
11:52 PM
well played
 

« first day (495 days earlier)      last day (2358 days later) »