« first day (53 days earlier)      last day (2806 days later) » 
15:00 - 20:0020:00 - 23:00

user4710450
3:50 PM
Hi all
 
@Ehsan Hello.
 
user4710450
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <conio.h>

int main() {
// char temp_filename[] = "/sdcard/temp_file.XXXXXX";
// int fd = mkstemp(temp_filename);
// unlink(temp_filename);
int fd = open("hello.txt",O_RDONLY|O_CREAT);
char *name = "Ehsan";
write(fd,name,sizeof(name));
close(fd);
// getch();
return 0;
}
 
user4710450
How does this code looks like?
 
it looks like shit and you shouldn't be dumping code in here (plus it's C, even)
 
@JerryCoffin your fault ... ALL YOUR FAULT!!! :p
 
user4710450
3:51 PM
It doesn't write anything to my Android phone
 
user4710450
It generates hello.txt
 
user4710450
But the size is 0 bytes.
 
@Ehsan Broken. You've defined name as a pointer to char, so the amount it writes will be the size of a pointer, not the length of string.
 
user4710450
So, What should I change to make it work?
 
perhaps not writing to a file you open in readonly mode would be great?
also checking error codes?
and reading the rules of this room?
can you even breathe on your own
 
user4710450
3:53 PM
No error code
 
Open for writing, then char name[] = "Ehsan"; write(fd, name, sizeof(name)); would at least be a start.
 
user4710450
please be a bit nicer to a newbie, 😭😭😭😭
3
 
user4710450
@JerryCoffin Thanks. 😃
 
@набиячлэвэли It's all right for now--things are pretty slow at the moment.
 
user4710450
@JerryCoffin What mode should I use?
 
3:58 PM
@Ehsan O_WRONLY would be a starting point.
Of course, we mostly do C++ here, so we'd typically do std::ofstream os("name"); os << "Ehsan"; and be done with it.
 
user4710450
Well funny
 
user4710450
It isn't creating anything
 
user4710450
I guess it has something to Do with my phone Not being root
 
@JerryCoffin Ah. Right. I stand corrected.
 
@Ehsan The discussion so far has been slightly off topic, but rooting phones would be a long ways off topic...
@Griwes Oh, no need to stand. Kick back and relax...
 
user4710450
4:03 PM
OK, I fixed it
 
@JerryCoffin I'd relax if my pizza was here already. :D
 
user4710450
I Just used this O_CREAT | O_WRONLY
 
user4710450
Yet another problem
 
user4710450
It seems sizeof(name) is returning 4
 
user4710450
Shouldn't it return 5?
 
user4710450
4:08 PM
😭😭😭😭 extremely dumb I guess
 
18 mins ago, by Jerry Coffin
@Ehsan Broken. You've defined name as a pointer to char, so the amount it writes will be the size of a pointer, not the length of string.
 
@Ehsan Addressed in my first comment. You want char name[] = "Ehsan";Oh, and that'll include the nul terminator in the length, so you'll get six, not five.
 
@Ehsan I think you want strlen(name) not sizeof
 
@caps That works too, but it's not really necessary for this case.
 
@JerryCoffin Ah, so sizeof(char[]) returns the length of the array?
 
user4710450
4:13 PM
No it return the size of the pointer
 
@caps Of course. sizeof(array) always gives the size of the array. An array of char is no different.
 
if the array is a static array
 
@JerryCoffin TIL about C
 
@Ehsan sizeof(a_pointer) (which is what you had) gives the size of the pointer. sizeof(an_array) gives the size of the array.
 
It seems like sizeof(array) would return something that could be reasonably compared to sizeof(type)
char* strings[1]; char* name = "Ehsan"; assert(sizeof(strings) < sizeof(name)); is very unintuitive to me.
I guess you would have to do something like assert(sizeof(strings) * sizeof(char*) == sizeof(name)); which is, as I said, not intuitive.
 
4:19 PM
@caps sizeof(T[N]) == sizeof(T) * N
 
 
1 hour later…
5:35 PM
Oh lambda expressions, they're soo odd to learn
Yeah, i guess ill have to read about them. Got used to being able to piece together how to do something without having to read about it lol.
 
5:59 PM
Hello all
 
 
1 hour later…
6:59 PM
quick question fellas, someone's arguing with me about my logic being incorrect, im pretty sure it's correct
he keeps aying i need to use ||, but i think he's completely wrong on this. I want to check for all 3 values not being equal, so i would use && would i not?
 
7:15 PM
dear God I think that code gave me cancer
 
yawn, would you prefer i use a lambda expression lol
 
nwp
for loops too hard, especially range-based ones
 
I think I'd prefer that you had at least some idea how to actually use the language instead of just how to make the compiler not error
 
what's wrong with my code, if i weren't using c++11 that'd how you'd transverse through the map is it not?
 
um
stricmp?
szType? nPlayerArg?
go back to school
 
7:19 PM
never went to school at all
just taught myself
so you dont like stricmp b/c why, it's os dependant or something?
and you dislike hungarian notation?
 
hungarian notation was written by idiots, for idiots.
 
if you say so, so in other words, you dislike my usage of 1 function, and hungarian notation
 
and stricmp is part of C string handling and therefore de facto banned from any codebase worth using
 
Everybody hates hungarian notation
 
im a fan of it personally, it makes it clear what a variable is
without you having to go to its definition
 
7:20 PM
er
ever heard of an "environment"?
it's this fancy thing where you just mouseover a variable and then it tells you right there what it is.
 
@Jeff It doesn't make that clear. The best it can do is /not/ cause confusion
@Puppy Er. Worst argument ever :)
 
If you think it doesn't make it clear i can't argue with you, that's an opinion based thing
i just personally prefer to see int nVal1 instead of int Val
then 100 lines down see if(val1 == something
 
nwp
@Jeff your sample is not that long, that pretty much amounts to "everything"
 
oh god why a numeric suffix?
 
it's not long no, so i don't really need any clarification
but, it's habit by now
and yes puppy, i use visual studio 2015, im aware i can hover
that's not the point
 
7:23 PM
it's absolutely the point.
Hungarian Notation is just an out-of-date manually-maintained failed Intellisense.
you'll need some bloody complex notation to indicate interesting types, and every time you change the type of anything, you'll have to rename every usage.
 
@Jeff You're doing a linear search through a map? Writing all kind of ugly dereferences left and right? You're using while + continue to "mimick" a normal for loop, but badly?
Also, is this correct: for a match to be found, only one of the three values needs to match?
@Puppy Please. Hungarian is the none issue, stop noising.
 
not to mention things where you don't know the type.
 
for a match to be found i wanted all 3 to be equal
hence why i used &&
 
@sehe stricmp is pretty awful too.
 
nwp
@Jeff you should put a code snippet on codereview.stackexchange.com some time and see how much it can be improved (make sure it is actually on topic there)
 
7:24 PM
yawn
 
I do want to change it to a lambda expression though, im trying to use more a more up to date coding style
 
I dunno, I think that if you think that Hungarian notation and stricmp is a good thing to do, you clearly need a lot more help than just a few &&s.
 
that's your opinion, and i know many peopel who share it
 
@Jeff I agree about Code Review
 
i also know many people who still use hungarian notation
yeah, i thought about it, but you get guys liek Puppy who just wanna bash ya
lol
 
7:26 PM
if ya write terrible code, it'll get bashed
 
So... you come here?!?!? Pretty impressive rational process
 
anyways, ik the cleanest way to handle it is with a lambda, i was just wanting to verify
if that guy was right about my logic being incorrect
 
@Jeff CodeReview cannot possibly bash, because they exist to do code review
 
pretty sure it was right anyways, i debugged, logged, etc
 
hmmm
 
7:26 PM
and it was triggered as it should be
 
stricmp and hungarian in a lambda
 
Lounge can bash, because we're here to hang out. Not to be annoyed with icky code.
 
that is an amusing thought.
 
well, true i suppose, i should have asked elsewhere ill give ya that
 
7:27 PM
@Jeff have you even seen my comments about your code? If you had posted on CodeReview, you might not have missed it. I feel I'm wasting my time.
 
no i indeed saw it
 
@Jeff val1 and nVal1 are equally terrible names...
 
@Puppy ... stop it. You've been heard.
 
and like ive said a few times now, i realize that the best way to do it is with a lambda expression
 
@Jeff So. What made you decide not to answer?
 
7:28 PM
@Jeff If you have to go up 100 lines to see where you defined a variable, your functions are way too long.
 
@Jeff I've said literally NOTHING about that.
 
no im aware, you said my code was ugly, which i agreed with
and i know a nicer way to do it woudl be with a lambda, and not with a while loop with ++itor and continue
lol
 
nwp
@Jeff I don't think a lambda will save you there
 
@Jeff FFS. Instead of rambling without a clue. GO BACK and actually read what I said.
I'm clearly wasting my time.
 
If you say so lol
I read exactly what you said, you're the one with the hostile attitude lol.
 
7:31 PM
?
 
Do i need to clarify?
lol
See i can be hostile and irritating too, anyways, lets end the topic.
I'd rather not pointlessly argue with you
 
I didn't accuse you of hostility either.
 
I never said you accused me of hostility, I'm saying your attitude is bad.
 
@Jeff You haven't addressed some of the first things he said, e.g. (*itor) and a linear search of a map
 
15 mins ago, by Jeff
yawn, would you prefer i use a lambda expression lol
 
7:32 PM
> you're the one with the hostile attitude lol.
Implying that you're not. Or that it's somehow relevant that you think I am
 
Not at all, I'm chill lol.
 
Do you understand how map works at all?
Have you read the API?
 
I wasn't talking about that. I was wondering why you don't start, e.g. by answering this question:
9 mins ago, by sehe
Also, is this correct: for a match to be found, only one of the three values needs to match?
Other question: what is the key into the map?
 
for(auto itor = map.begin(); itor != map.end(); ++itor)
{
if((*itor).second->nType == nType && stricmp((*itor).second->szType,szType) && (*itor)>second->nID = nPlayerArg)
return (*itor).second;
return nullptr;
}
sorry about the indention
and the key is the type
which is indicating the matchtype you're in
0 woudl be a deathmatch, 1 would be capture th eflag
 
nwp
@Jeff edit it and press the fixed font button that appears
 
7:34 PM
@Jeff as in, szType?
 
szType is badly named, i haven't cleaned it yet. that's supposed to be indicative of a achievement type string
so for example
 
@Jeff "the type"? Like, the same as sdType? Why is the key not what you want to lookup by? Or why is it not just a vector/list?
 
<ACHIEVEMENT id="0" <!--deathmatch--> AchievementType="Kills"
 
@Jeff Wait.
What.
You're saying szType is a string that is holding an integer?
 
no no
 
7:35 PM
@Jeff Glad to know it's properly Hungarian though :) Nevermind that we don't have a clue what it means :)
 
And you're doing a str**i**cmp on it??
 
(SCNR)
 
@sehe lol
 
caps, im doing a stricmp on szType and achievementtype
 
@caps Kills is an int?
 
7:36 PM
@sehe id="0"
 
but yeah you're 100% right i shouldn't be using a map, a vector fits it much better
 
My other question is still waiting. Mind you, that's actually about the likely logic error you were asking about... :(
 
@Jeff sigh
 
Mind repeating what your question was sehe
 
No way
4 times is quite enough
 
7:37 PM
@Jeff You can scroll up. ;)
@Jeff Here's a hint. Here's a bigger hint.
 
I think he was too busy typing. But now he takes his time
 
ohh, the map thing yeah, im already changing it to a vector. it was originally a map b/c i was actually looking it up by key i guess, and just never changed it once i did my own find function
 
@Jeff My spidey sense says you just need to make the "key" (rather, the comparison predicate) such that the lookup does what you want.
It makes no sense to "fake a map loopup" using handwritten algos on a vector, just because you don't know how to make map lookup work
 
@sehe @Jeff If there were reasons other than the lookup that you went to vector they may be satisfied by multimap
 
@caps Possibly
 
7:40 PM
@sehe Right. May.
 
yeah, multimap would definitely fit since I have multiple keys that are the same value
 
If you still want to do vector, please consider find instead of that awful for loop.
 
@Jeff Google "equivalent keys" or "strict weak total ordering"
@caps For the code given, that is find_if and should be done :)
 
@Jeff Maybe. It sounds like your actual key is based on three properties, so you may want a map with a custom predicate, as sehe was proposing.
 
I mean, as its written right now with the multimap if i dont change it to a vector
i should be able to just do somethign like
auto itor = std::find_if(map.begin(),map.end(),[&](const auto& item) {return blahblah;});
correct?
and then if itor != nullptr return itor.second
 
7:44 PM
@Jeff No.
 
@Jeff yes. And the performance would likely be atrocious
@Jeff map.end(), not nullptr
 
oh sorry
 
You are barking up the wrong tree.
 
woof!
 
template<

    class Key,
    class T,
    ***class Compare = std::less<Key>,***
    class Allocator = std::allocator<std::pair<const Key, T> >
> class multimap;
 
7:45 PM
Puppy barks at every tree just to make certain!
 
@caps But it's fun. And dogs learn from barking up to several trees and observing the effect
 
@Jeff That would be if you are using vector, sure.
 
@sehe No, they really don't ;p
 
@Jeff Although as sehe pointed out, that will compile and run just fine. It's just... then you will have defeated the whole reason for using the multimap over the vector in the first place.
 
Gotcha
 
7:46 PM
@Puppy Pfft.
 
I guess a vector does suit my purposes better in this situation then
 
@Jeff Does it now?
 
@Jeff Nobody knows:
 
Lol, okay, I give up.
 
7 mins ago, by sehe
It makes no sense to "fake a map loopup" using handwritten algos on a vector, just because you don't know how to make map lookup work
 
7:47 PM
Pretty sure, if I'm just wanting to check 3 values and ensure they're equal to my arguments
 
@Jeff SMH
 
@caps You're the one hung up on shoe-horning into associative container. Fact is, we can't tell whether it's appropriate
 
@sehe That's true. He hasn't given us enough information. But he doesn't seem interested in doing so.
 
I can show you exactly how it's being called if you want
 
@caps His loss?
 
7:48 PM
for example if im calling to check a successful flag capture, it'd be
 
@Jeff We don't need that. You need to know the use patterns for your data. Start with the pending question... :(
No more code. Please. It's noisy as it is. Code Review is patient
 
kk, sorry
 
Hello

I have this little snippet of code, and I don't entirely understand the syntax.
Problem it is in a static class, and therefore I can't use this. I have tried to replace "this" by the static class name, but it didn't work. Help?
socket.async_receive_from(asio::buffer(recv_buffer), remote_endpoint,
[this](std::error_code ec, std::size_t bytes_recvd){ this->handle_receive(ec, bytes_recvd); });
 
nwp
Aug 19 at 11:58, by nwp
Got a C++ question? Go to the C++ room!
 
@nwp That room is empty... :(
 
nwp
7:53 PM
in C++ Questions and Answers, Aug 30 at 7:36, by milleniumbug
You don't ask a question because room is empty? Well, it's empty because you haven't asked the question!
 
Please someone help me. This should be very quick if you know how
Hello

I have this little snippet of code, and I don't entirely understand the syntax.
Problem it is in a static class, and therefore I can't use this. I have tried to replace "this" by the static class name, but it didn't work. Help?
socket.async_receive_from(asio::buffer(recv_buffer), remote_endpoint,
[this](std::error_code ec, std::size_t bytes_recvd){ this->handle_receive(ec, bytes_recvd); });
 
Anyways, Sorry if i irritated you guys, wasn't trying to. My original question was just if the logic worked since someone was debating with me whether or not i was correct.
 
3 messages moved from Lounge<C++>
 
I already knew the code was nasty lol
 
@Jeff My question is still pending.
 
nwp
7:54 PM
@KaareZ what does this refer to in the original code?
 
It's amazing how much noise all sides have generated.
25 messages moved from Lounge<C++>
 
The class which the function is in.
 
If you're referring to the question of what my key was in the multimap, the key was nType
 
since that's the first variable i entered into myxml
 
nwp
7:55 PM
can you make handle_receive static too?
 
It is.
It's in a static class named Network
 
id="0" <!-- this = matchtype, this was the key-->
 
everything else was just extra information i was using to verify that specific achievement requirement was met
which is why i said i probably shouldn't have started with a multimap in the first place, i could have just did auto itor = find_if(stuff
and called it a day
 
nwp
if handle_receive is static then you don't actually need this and you can replace it with [](std::error_code ec, std::size_t bytes_recvd){ Client::handle_receive(ec, bytes_recvd); });
 
7:58 PM
TBF. My intuition says this is ASIO code and it needs to be non-static. But @KaareZ doesn't know about the shared_from_this pattern to keep objects alive
52 messages moved from Lounge<C++>
 
@nwp Hmm. It won't compile
 
15:00 - 20:0020:00 - 23:00

« first day (53 days earlier)      last day (2806 days later) »