« first day (703 days earlier)      last day (2149 days later) » 

Sam
7:51 AM
I've got a vector which gets passed to my program via a DLL.. I've also got an enum which has names for each of the inputs which correspond with their position. To make my code cleaner, I've made a class to hold all the inputs of the inputted vector (which has 40 elements). Is there a way I can make use of the enum to assign my member variables without having to declare them all singularly? It gets a bit chunky.. See here for an example pastebin.com/z27eqcLB
 
nwp
Put position1 to 3 into a container and then use std::copy.
 
Sam
Sorry, what's a container? XD
 
nwp
std::vector for example. Something that lets you iterate over the positions.
std::array will probably do since you have a fixed number of them.
 
Sam
OK. But then whenever I want to reference a member with an object I'll need to use the container right? i.e. classObject.container[2]
 
nwp
Yes. Instead of thing.position2 you write thing.positions[2] which is not too bad.
 
Sam
7:58 AM
And I guess I can substitute that index which the enum anyways.
 
nwp
If you don't have a position0 you need to change the index accordingly.
 
Sam
Let me try this, thanks
Does an std::array hold different data types?
 
nwp
@Sam Depends on how you see it. It can't hold different data types but there are flexible types like std::variant and std::any.
 
Sam
OK because I have some double and some int
 
nwp
Storing the int as a double might work well enough.
 
Sam
8:02 AM
You able to show me a simple example on how to do the container and copy approach?
@nwp Yeah that's reasonable actually
 
nwp
std::copy(std::begin(arrayFromDLL), std::end(arrayFromDLL), std::begin(positions)); is the normal version.
Since arrayFromDLL looks like a pointer that's not gonna work and you need something like std::copy(arrayFromDLL, arrayFromDLL + number_of_positions, std::begin(positions));.
Also be a bit careful about out of bounds stuff.
 
Sam
8:44 AM
Great, thanks
It's actually an array not a pointer, it gets populated into some global array before manipulation, but yeah great :D
 
Sam
9:00 AM
This seem reasonable?
std::vector<double> myContainer;
double inputArray[] = {22, 23};
std::copy(std::begin(inputArray), std::end(inputArray), std::begin(myContainer));
std::cout << myContainer[0];
 
nwp
No, that accesses myContainer[0] and myContainer[1], neither of which exist.
You either need to get some memory with myContainer.resize(2); or use std::back_inserter(myContainer) so that it uses push_back to insert the numbers.
 
Sam
Ah, I need to set size of the container equal to the size of the array before copying
myContainer.resize(sizeof(inputArray))
 
nwp
sizeof gives you the size of the object in bytes. That's not the right number of elements for the vector.
If you have C++17 you can use std::size(inputArray).
std::end(inputArray) - std::begin(inputArray) is an alternative.
 
Sam
Awesome thnaks
Wait it would be a pointer if i'm passing an array into a class constructor wouldn't it
 
std::array to the rescue
 
Sam
9:15 AM
Yeah I can't really change that atm
@nwp This works perfect. Thanks
 
 
1 hour later…
10:48 AM
Hey guys, I would like ask a dump question...
 
Visual C++ is not open sourced right? Then when I click "go to definition" in Visual Studio. I see some source code. What are these?
Are these not source code?
 
That's most likely the source code that happens to be a part of the header file of their C++ standard library implementation
(obviously, the header files must be readable by the compiler)
 
@milleniumbug ok thanks.:D
 
hmmm, if I understand this answer, it would mean the standard library source code is publicly readable by everyone
(so, headers and the implementation too)
of course this doesn't mean it's open source, because open source would allow you to reuse that code for your own stuff
 
10:57 AM
hmmm, I see the difference
 
open source != source available to read
 
?
open source can't read source code?
 
this is a snippet from my paint method that i not like...maybe someone can help to do it more effective in the case of save lines and code. coliru.stacked-crooked.com/a/0a82b72932c41cf7
 
Never mind, I merely need to know if I were jumping to Visual C++ source code by clicking "go to definition" in Visual Studio. :D
 
> Open-source software (OSS) is a type of computer software whose source code is released under a license in which the copyright holder grants users the rights to study, change, and distribute the software to anyone and for any purpose.
If they don't allow you to change it nor redistribute it, then it's not open source then
 
11:05 AM
ok, i see.
@milleniumbug I read some posts about the difference about file open mode between "text" and "binary". And the only reason I can find to prefer text mode is for the newline conversion.

I've read something here:
https://www.gnu.org/software/libc/manual/html_node/Binary-Streams.html
”Since a binary stream is always more capable and more predictable than a text stream, you might wonder what purpose text streams serve. Why not simply always use binary streams? The answer is that on these operating systems, text and binary streams use different file formats, and the only way to read or write “a
 
Personally I wouldn't use text streams for anything
also, yes, text streams do newline conversions, but not in a way you'd like
 
then you have to do the newline conversion on you own then
 
Ron
How relevant are design patterns in todays world, especially when talking about modern C++?
 
design patterns are tools
 
11:10 AM
GoF design patterns are mostly overrated
 
Ron
Does that mean they don't have to to be used.
 
Ok. Then I would follow your advice.
 
there are design patterns which are specific to a domain, and some of them are fairly useful
 
and the GoF doesn't have all patterns that are commonly used
 
@milleniumbug sir, did you write your own functions to do the conversion?
 
11:12 AM
yes
shouldn't be too difficult
 
Ron
Do I use smart pointers in implementing gof patterns or not?
 
GoF patterns don't talk about specific implementation, so you're free to do that
 
don't implement a pattern to implement a pattern
 
Ron
That's quite some hard and boring reading for me so I am reluctant to go over that entire book.
 
design patterns in general are a bit like cooking recipes, so people can (and will) modify them to their needs
 
11:14 AM
write the code that solves your problem, if it looks like an existing pattern then fine, if it doesn't then meh
 
Ron
I see.
I guess I must read it then. Appreciate it.
 
It's worth reading, if only to understand what other person may mean if they say the name of the pattern, but otherwise don't sweat too much about them
 
Ron
I see. I wonder why there isn't a book of idioms.
I guess Meyers books come close to that.
 
std::istream& readline(std::istream& is, std::string& out)
{
    // is must be a binary stream
    if(std::getline(is, out) && out.back() == '\r')
        out.pop_back();
    return is;
}
 
@milleniumbug Sir, one last question for this. So for SFTP client like WinSCP, I should always use binary transfer mode right?
I guess that the 'text mode' might do some newline conversion?
 
11:23 AM
Don't use text mode
thankfully no one actually supports text mode for SFTP
 
Ron
11:34 AM
How do you approach class design?
Is there some quicker route other than experience and gathering bits and pieces?
I've read quite a few dogmas from the CPP Core Guidelines and I am non the wiser.
 
I start with gathering design requirements
 
first decide whether you actually need a class in the first place
 
why is this code going in infinite loop, I am sending 1 line at a time to func
  fo.open(filename.c_str());
  char buffer[101];
  int size = 100;
  int index = 0;
  std::string data;
  while (fo.good()) {
    fo.read(buffer, size);
    buffer[size] = '\0';
    index++;
    data = data + std::string(buffer);
    int breakline = data.find('\n');
    while (breakline != std::string::npos) {
        std::string fullline = data.substr(0, breakline);
        data = data.substr(breakline+1);
        if (fullline != "")
 
this looks like long-winded, error-prone, badly performant way of saying
fo.open(filename);
while(std::getline(fo, data))
{
    if(data != "") func(data);
}
 
@pythonRcpp that's easy to break, I'll just pass it a file with a single space in it
use the code milleniumbug posted
 
11:47 AM
data = data + std::string(buffer); is about the most horrible way of concatenating a null terminated char array to a string,
 
@milleniumbug no fo is a zlib.h function that does not have a getline
 
fo is not a function
 
object it is
 
also, please show the declaration of fo
 
is there a way in C to declare a function prototype with a function as an argument
without specifying the function argument's name?
i'm trying to do void traverse(Node *, void *, void ()(void *));
 
11:51 AM
data.append(buffer, size); is much better and won't allocate 3 temporary char buffers
@AfonsoMatos you cannot take a function as an argument, only a function pointer
 
function parameters don't exist, they're actually treated as if they were function pointer parameters
 
i am simply trying to send each line to func ... i know its badly written
 
2 mins ago, by milleniumbug
also, please show the declaration of fo
 
ZlibFileHandler fo
 
yeah that's what i'm trying to do
i guess just void (void *) works
 
11:57 AM
@pythonRcpp it's your own type?
 
If I've got a struct A that contains a function F and if there is a function with the same name outside of the struct - to refer to the outside function I use : : F?
 
@pythonRcpp that's a horrible class to wrap a file resource like a file
 
12:03 PM
@milleniumbug the link you shared looks way better, but i am not sure how to use it
use in the sense , what files to copy
 
the two files in the src directory
 
and an example of how to use it in code is in the examples dir
 
trying . Thanks guys. i will ask if i face more issue
 
12:26 PM
i included both the files
but getting
In file included from zstr.hpp:16,
                 from MYcpp:13:
strict_fstream.hpp:52: error: expected ‘;’ before ‘noexcept’
strict_fstream.hpp:53: error: expected ‘;’ before ‘private’
 
what ancient compiler are you using
(g++ -v)
 
12:42 PM
@milleniumbug sir, I was using WinSCP under stfp to test. I can use "text mode" with SFTP and it did make the newline conversion.
Just wanna let you know that, nothing else.
 
hmm ok
 
:D time for FIFA
 
 g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
 
that's a 6 year old compiler
 
:( is there no way to fix this except compiler upgrade
GNU C++ (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-4) (x86_64-redhat-linux)
	compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9beacdb5724f8325308f81d8bbfbf884
In file included from zstr.hpp:16,
                 from MYcpp:13:
strict_fstream.hpp:52: error: expected ‘;’ before ‘noexcept’
strict_fstream.hpp:53: error: expected ‘;’ before ‘private’
 
12:54 PM
why can't upgrade compiler?
 
legacy codebase and very old company
 
sucks :(
you could try replacing noexcept with throw()
 
ok trying
got a gcc 4.8.3 !
 
4 years old is still better than 6 years old
so, nice
 
ok so now it compiles
without changing noexcept to throw()
but on running it gives /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found
 
 
3 hours later…
3:51 PM
hi guys
I have a 3D matrix , of sizes A,B,C (column major order)
suppose given ijk
i want to get the equivalent index that retrieves the element in the linear array
what's the the formula I should use?
 
4:10 PM
my program runs fine if i do export LD_LIBRARY_PATH=/mydir/gcc/4.8.3/lib64/:${LD_LIBRARY_PATH}
and then run my binary. if i do not do this , I get the error on running the binary like /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found . Is there something i can do while compiling so the path is exported automatically
 
nwp
@pythonRcpp -L/mydir/gcc/4.8.3/lib64
 
4:24 PM
weirdly does not work, but works if i use export on terminal and then run the binary
 
 
4 hours later…
8:30 PM
can I compare 2 iterators to see if they are on the same position
 
that's the way to see if you are at the end of a range
 
awesome thanks
 
8:45 PM
what are these __M__something functions in vector?
 
ignore them
private implementation details
 
9:14 PM
identifiers starting with 2 underscores or underscore and capital letter are reserved for use in the compiler/standard library headers
messing with them is undefined behavior
though practically they have some that they'll use for private members
 

« first day (703 days earlier)      last day (2149 days later) »