« first day (285 days earlier)      last day (2558 days later) » 

1:13 AM
Hello, I am trying to change the value of a static int that has been declared in my class's header file in one of it's method implementations. However, the compiler is telling me I am making an undefined reference
 
Double check that you are declaring your class (and its members) in a header somewhere before you actually implement the class.
 
Most likely you didn't prefix the variable with the class name, aka int Class::static_member = 12
 
That was the issue, I was forgetting to initialize the int the implementation. Thanks for the help! :)
 
 
7 hours later…
vin
8:02 AM
Hi, this is about regex. I want to process data in this form: <pattern>, <pattern>,... How can I detect bad patterns if any? The regex_iterator returns only valid matches. I am unable to figure out what is to be done with regex_search and regex_match. Do I have to tokenize first or can this be done with regex alone?
 
Xeo
1 message moved from Lounge<C++>
 
 
3 hours later…
11:06 AM
My earlier solution was not ok.
I want to prevent user from calling a function with container which value_type is different from other template parameter. I know that clearer way would be to use static_assert, but I want to try out std::enable_if.
 
nwp
what is stopping you?
besides that preventing users from doing somewhat reasonable things is not a good idea
 
template<typename StringT, typename Container = std::vector<StringT>>
auto split(StringT&& toSplit, StringT&& delim)
-> std::enable_if_t<std::is_same<StringT, Container::value_type>()>
This code has some error in std::same
error C2923: 'std::is_same': 'Container::value_type' is not a valid template type argument for parameter '_Ty2'
 
nwp
std::enable_if wants a bool, but std::is_same returns a std::true_type or std::false_type, not the same thing
you need to add ::value to get the bool
 
But there is that () at the end.
 
nwp
@Horttanainen that creates a std::is_same object
 
11:22 AM
What really?
I disagree. I check the reference again.
 
nwp
yeah, similarly to how std::string() creates a temporary std::string
 
hmm
Shouldn't this then fix the problem:
template<typename StringT, typename Container = std::vector<StringT>>
auto split(StringT&& toSplit, StringT&& delim)
->std::enable_if_t < std::is_same<StringT, Container::value_type>{}() >
 
nwp
@Horttanainen looks reasonable
 
It gives the same error.
So does adding ::value
 
nwp
apparently there was a typename missing, but otherwise it works
 
11:29 AM
uhhh Sorry about wasting your time.
Thanks
 
12:16 PM
btw MSVC 2017 cannot handle this:
template<typename StringT, typename Container = std::vector<StringT>>
auto split(StringT&& toSplit, StringT&& delim)
->std::enable_if_t < std::is_same<StringT, typename Container::value_type>{}() >{}

I had to use ::value
 
nwp
you can try std::enable_if_t<std::is_same_v<StringT, typename Container::value_type>>
I heard VS is C++17 library compatible, so it might actually work
 
@nwp you need to use a flag to enable this
 
@Mgetz I tried it. it works fine
 
@Horttanainen good to know, I had to use the flag to enable non-const data members
 
1:18 PM
the sendall() function from beej's guide is intended to be used with stream sockets only, am i right.?
not with datagram.
send on datagram socket can return zero length.
 
1:41 PM
omg, everything ok.
 
 
7 hours later…
8:21 PM
Hi Guys. I want to understand more clearly difference between C++ platforms. Could someone explain me, why if I build lib under Linux for 64bit architecture, it will not compatible with windows for example?
 
sup? How do I divide integer while truncating result upwards? My best guess is:
m/n + m%n?1:0
but that does not work with negatives
 
or why in android community - there is a bionoc project - as a replacement for libc, libm etc. Why I can't just use "standard" libs?
@EuriPinhollow check floor and round functions
 
@silent_coder "Could someone explain me, why if I build lib under Linux for 64bit architecture, it will not compatible with windows for example?" - because it is hardcoded to calling convention and exception model even if you do not use platform-specific funcs. Also, some funcs can be source-based in one platform and not in the other I suppose.
 
@EuriPinhollow i think this should be covered with 'standard' somehow? ok, nevermind to windows, but Android is based on linux, but still looks incompatible with linux libs
 
@silent_coder that's nice but I'd prefer doing this without going to floating point.
@silent_coder I am not an expert but Android is modified Linux. There is probably a diff which lists all differences. Some of them are probably affecting machine code compatibility.
 
8:31 PM
@EuriPinhollow ok, regarding machine code, seems like clang for example could crosscompile to different platform in android mode, if I compile lib with clang in android-arm mode - will it work on android?
 
nwp
17
A: Why are "Executable files" operating system dependent?

Alexander GesslerIn order to do something meaningful, applications will need to interface with the OS. Since system calls and user-space infrastructure look fundamentally different on Windows and Unix/Linux, having different formats for executable programs is the smallest trouble. It's the program logic that wou...

 
@nwp so static libs "in theory" should be compatible?
 
nwp
@silent_coder yes (assuming the compiler's target and the platform are compatible)
@silent_coder no, because they use the wrong system calls, the wrong calling conventions, the wrong interrupts and the file was created in a format that the linker doesn't understand
nothing that cannot be overcome, use a smarter linker, write some wrappers to fix the calling convention issue, catch system calls / interrupts and translate them into the format that the OS understands
 
how system call could be wrong, if it's say call function "abc" from stdlib and pass integer with value 5 into it (just for example). This seems to be "standard", or what I'm missing?
 
nwp
and then you end up with wine or the linux subsystem for windows 10
 
8:38 PM
@silent_coder are you asking whether you could compile clang for android? Somebody probably did it already. Yes, completely possible.
 
nwp
@silent_coder it is not standard how to pass the 5 for example. Some systems will put the 5 in register eax, others will put it on the stack. Then sometimes the calling function is responsible for cleaning up the stack and sometimes it's the callee.
 
To be true my main problem is Linux/Android. I implemented lib wich doing some AI computations, it's compiled and work fine in Linux, and my intention was to use it as static libs linked to android app. But now when I'm trying to compile whole project it's broken, and all the time complain for lack of some function
 
@silent_coder let's begin with that it may well be not there: it can be written in header files and not exported. Now, if you want to call anything from anywhere, you are using smoe calling convention, or interrupts, or exception model, whatever. If they do not match - bam.
 
nwp
ah, then there is the issue with name mangling.
@silent_coder which function?
 
so if let's say there is aligned_alloc missed in android's stdlib than there is no chance my code will work on android, if I use this function in my code?
 
8:43 PM
@silent_coder Are you sure in that you are using Linux and Android on the same architecture?
@silent_coder Basically: yes.
 
nwp
@silent_coder you can write your own aligned_alloc, put it in a lib and link that
 
I see
 
nwp
or just put it in the executable, no need to make an extra lib actually
 
@nwp even if he does he may still break something in process. But well, if the ilbrary has no external dependencies, it may well be possible. If the calling convention is exactly same that is.
 
I thought that if lib is static, than it's selfcontained, it cointais all what it needs inside. But seems like this is not true when thinks connect with system functions?
 
nwp
8:47 PM
anyways, what you are supposed to do is use the right system (android studio?) that has a compiler set up that produces all the right things
 
ok, but clang is based on llvm - which goals is to "mimic" unified env somehow, right?
 
Why can't you compile it for android BTW?
 
@EuriPinhollow maybe I could, but I not sure it will work if I don't using Android NDK toolchains. And actually that's the question I want to understand. Will it work or not. =0)
 
@silent_coder of course you need something which has "android" in it's name.
 
Sorry guys if my questions seems stupid for you. But i'm not natively C++ developer, so my main background from other languages. I understand that in Java or in .NET there is VM behind code which make actual code platform independent. I also understand that in normal C++ world there is no VM behind code, so compiler/linker actually compile platform specific code with all low level stuff you mentions (calling conventions, interrupts, etc)
so in that case - what is a difference between GCC compiled code and CLang/LLVM if I still can't reuse any artifacts on different platforms?
@nwp Sorry, I don't get how put code into executables could help me in that case? My native code just making some computations, but the main app is written in java and java manage device UI, db, server - etc.
 
nwp
9:05 PM
@silent_coder so you have a c++ library that gets called by Java? I assumed you had a C++ program that is missing a symbol, in which case you could just define it.
 
yes, I have an android app, and c++ lib, and now trying to be able use that libs from app
 
nwp
well you need to provide the symbol somehow. Can clearly be done in C++, not sure if Java can produce symbols that can be linked properly.
although that seems like a symbol that your standard library should be providing
 
java could call C function with different technologies, like java-jni. So there is a shared library writen on C++ as connector, android app, and my static lib.
static lib linked to those shared lib - connector
 
@silent_coder LLVM is not in any way virtual, it is not an acronym at all. LLVM is a project name, not a virtual machine name.
@silent_coder In C++ and native code world every compiler+OS+architecture combination is a unicorn until proven otherwise. Clang is a native code compiler, an analog of gcc.
 
@EuriPinhollow I understand that, but I thought that it's intention is pretty similar - guarantee "similar" env.
 
9:19 PM
@silent_coder similar programming environment (STL/stdlib, POXIS, whatever) is not same as similar execution environment.
@silent_coder Native code being portable means that one can compile it for any specific machine and it will work there, not that it will be compiled once for everything.
@silent_coder when you are using C++ library only, you are writing potentially portable code (given that it contains no errors because of implementation-specific behaviour).
 
@EuriPinhollow But seems like for Linux/Android even dev. env are different
 
@silent_coder Dev env is not the same as programming env i.e. API.
 
programming env. =0)
 
@silent_coder .NET is not same as JVM.
 
@silent_coder You actually can reuse artifacts on different targets. Clang is a compiler front-end. It produces LLVM-IR as its output. Then various tools from LLVM manipulate LLVM-IR in various ways--the obvious ways being optimizing it, and generating code for some target from it. So you can splice different LLVM back-ends to the Clang front-end relatively easily. That said, it's still usually done as a programming project, so you get a complete compiler that just produces native code.
 
9:29 PM
ok, so threre is a list of services OS offfer to any program, and some lind of lib is just a wrapper for that calls, and that libs significantly different from platform to platform?
@nwp @EuriPinhollow @JerryCoffin thanks for all your answers and time. You are doing really good things answering there.
 
@silent_coder Not really. It doesn't (even attempt to) automate generating a standard library for each target. Somebody has to port the stdlib to a target, and to use it, you link to that library.
 
@silent_coder you forgot calling convention, exception model and interrupts.
 
That said, there are really only a fairly small number of places the standard library has to interact with the underlying platform: open/close/read/write files, allocate memory, create a process, etc. At a wild guess, probably only a few percent (maybe less) really has to work directly with the OS.
 
hi guys
anybody here?
 
@user8469759 Sorry, but no. Nobody here at all.
 
9:41 PM
=D
I have a question
I actually asked it yesterday
time ago I've submitted some code for a review
 
@user8469759 I have the answer to life, the universe and everything (but I still don't completely comprehend the question).
 
and basically it has been pointed out that sometimes it's better to use POD
instead of complicated classes etc
I was wondering if you could tell me when a POD should be used
the context was a list class,with a node class
using templates
and there was also an iterator implemented
but my question is more general when should I prefer POD to classes with set and get methods et
etc*
 
@user8469759 Largely a judgement call--but having get and set members tends to indicate that you're doing something wrong, anyway. Whether the cure is a POD or a rewrite in some other direction...well, that's harder to say without looking at the specific situation.
 
can I show you the post?
 
@user8469759 Sure.
 
9:53 PM
7
Q: Generic List code with Iterator

user8469759I was wondering if this implementation of generic list with iterator is correct. The code compiles and goes fine. What would you think shall I improve? (first time I post here, I'm scared). I'm also concerned about the const correctness of the code. Class node #ifndef LIST_H_ #define LIST_H_ t...

I changed something since then but more or less is the same
 
10:13 PM
@JerryCoffin Floating point can be an issue too. Implementation can rely on OS FP emulation.
@user8469759 "sometimes it's better to use POD" - I do not see it mentioned anywhere on that pages, comments included.
 
@user8469759 In this case, yes, I think Node can be simplified quite a bit--but I'm not sure about making it an actual POD. In particular, I probably would include a ctor (but probably not a whole lot else). For example: stackoverflow.com/a/3479326/179910 is closer to how I'd generally do things (with the proviso that I rarely find linked lists useful at all so I usually just avoid them in general).
 
@user8469759 Strictly speaking, your class template is POD by C++ definition: you can memcpy it around because there are no sideeffects of relocating nodes. However, in this very case any kind of wrapping anything does not simplify using the class: you are already storing pointers named next and prev and getters/setters do nothing except assigning them and reading them. There is zero sense in adding that layer of abstraction because it is a built in feature of C and C++.
@user8469759 The only advantage you can take from getter and setter is to make them operate on references to exclude some number of asterisks in program which uses your library.
 
10:32 PM
@EuriPinhollow I wouldn't go quite that far. There are times a getter or setter accomplishes something useful. It just turns out to be a rare exception case, whereas many people seem to feel obliged to treat it as a the norm.
 
@JerryCoffin Well, I am talking about this specific case.
 
@EuriPinhollow Sure--and in this case, I agree.
 
why the use of set and get in my case seems to be wrong?
is it because they do something too much simple?
 
@user8469759 Yes.
 
that doesn't mean that implementing them is wrong...
I could change in future anything
 
10:45 PM
@user8469759 nobody said that.
 
@user8469759 Because they're adding only syntactic noise, not any real value.
 
ok anyway
for the POD
generally speaking
when is the POD useful instead of all that stuff
in my case is it because the node itself is very simple
so in that case I could have implemented it as nested class of the list
would that be better?
 
@user8469759 implemented what?
 
the node
instead of implemeting the node class with set and get
I could have implemented it as nested class/struct of the list class
 
@user8469759 ah I see. Yes, basically that.
@user8469759 However, the simpliest implementation of list does not even need separate container class, only the node class is essential.
 
10:49 PM
@user8469759 POD is a combination of two other things. It's generally more useful to look at the utility of those two other things ("trivial" and "standard layout").
 
I was trying to implement something like stl style
 
But in this case, the value isn't from POD per se, but from simply avoiding adding unnecessary complexity.
 
ah ok
 
@user8469759 Sure--and the linked-list I linked earlier does roughly the same (albeit, incompletely). Its node is reasonably complete though.
 
11:39 PM
I have an error, saying 'error: invalid use of void expression'
The line it says it on is this
otherVector.push_back(createMenuText(likes, Vector2f(vector.at(i).sprite.getPosition().x,
vector.at(i).sprite.getPosition().y + vector.at(i).sprite.getGlobalBounds().width/2 + 32), 0));
The implementation is here:
void Menu::createMenuText(string words, Vector2f position, int page) {
Text nText(words, normalFont);
nText.setOrigin(nText.getGlobalBounds().width/2, 0);
nText.setPosition(position);
if (page == Right) {
nText.move(640, 0);
}
nText.setColor(Color::Black);
text.push_back(nText);
}
And the declaration is here:
    void createMenuText(string words, Vector2f position, int page);
 
what are you pushing to otherVector
 
All the examples I found all had to do with people misusing threads
@milleniumbug createMenuText, a function that returns a specific edited object of class 'Text'
 
It doesn't return anything
The return type is void
 
OHHHHHH
That's embarrassingly obvious
@milleniumbug I had that same problem earlier, but it was on an overloaded function so I thought there was a different problem.
 

« first day (285 days earlier)      last day (2558 days later) »