« first day (1423 days earlier)      last day (2433 days later) » 

01:06
Why would something like this not work?
void up(position* x, int i, int j)
{
swap(*x[i][j],*x[i-1][j]);
}
position being a 3x3 matrix and swap being a predefined function
your code can't compile
as advice I would recommand you to avoid swap function in C
just use a temporary compiler will do the job
01:21
why avoid it?
that force you to use pointer of mix behavior with a macro...
I saw a lot of people code bug just because they use a wrongly their swap function or macro
How would I go about swapping values of a matrix?
in a function
as I say just use a temporary variable
but your code don't compile at all
That's a bad example
But in general i do wish to manipulate arrays
well, matrices
and swap all the time for what I'm doing
void toto(int *x) {
  int tmp = x[0];
  x[0] = x[1];
 x[1] = tmp;
}
21
A: Is there a built-in way to swap two variables in C

kennytmYes you need to define it yourself. C doesn't have templates. If such function does exist it would look like void swap(void* a, void* b, size_t length), but unlike std::swap, it's not type-safe. And there's no hint such function could be inlined, which is important if swapping is frequent (in ...

 
7 hours later…
08:24
@Stargateur It's not C, but Go allows you to swap quite nicely with:
func Swap(a []int, i, j int) {
	a[i], a[j] = a[j], a[i]
}
Just thought that was cool.
What have you been up to by the way? I've not spoken to you in a while.
C'est le dernier "block" de l'année scolaire pour moi. J'ai seulement un "thesis" qui m'en reste maintenant.
@JohnDoe If you're only swapping integers, and you want to save yourself from using a temporary variable, you can technically do the following (at the cost of more arithmetic operations of course):
a = a + b
b = a - b
a = a - b
That will swap a and b's value.
 
2 hours later…
10:36
@Micrified unless it overflows.
11:15
@Micrified haha ^^
I'm just search a good job, but I don't search a lot...
11:32
Yeah okay maybe it won't be so easy.
@Kamiccolo That's true, I didn't think of that
10 hours ago, by Stargateur
I saw a lot of people code bug just because they use a wrongly their swap function or macro
Just so you know, I wouldn't actually do this...
It was just a neat thing to show.
The cost of a single integer on the stack is so minuscule it's not worth trading for three arithmetic operations and assignments.
Anyways, right now I have a problem where I am protecting memory but getting a bus error instead of a seg fault signal. :<
It worked like 2 weeks ago.
Hmmm. Seems I might have to allocate with mmap and not posix_memalign.
11:50
@Micrified wtf are you doing xd
I'm trying to allocate and protect a memory page, then trigger a segmentation fault when accessing it so I can play with my signal handler. I am technically behind where I was in the past because something broke.
Likely because I was running it on Ubuntu not macOS.
The overall objective is to implemented shared memory.
I.E: I protect a memory page with a parent process, and the children processes trigger faults when writing to it. I then synchronize their memory.
I don't think you can do that with posix_memalign
That is useful.
No, I can't. But the purpose is different.
posix_memalign gets me memory.
12:06
@Tom's It sucks. He always ignores me. — Joey Yue 24 secs ago
this conversation is just hilarious
F*ck. Still a bus error. :/
WTF is going on there ...
(the linked question)
Poor guy. I think I get what he wants.
He wants to do something like <letter> - 'a' to get the numerical offset of the letter I think.
But can't express it well at all, and is quite confused.
Oh you think ?
I didn't understand anything with all these comments XD
Well I posted my interpretation. We'll see if he agrees.
What kind of job are you aiming at right now btw?
I can see a decent amount of postings on SO Careers site, but it's mostly mobile app developers and web stuff.
12:23
not these ;)
12:36
@Micrified maybe You don't have any proper filters set up?
@Kamiccolo No, maybe not. But I'm not really looking either.
 
3 hours later…
15:48
Hello. I have another question (sorry if it is daft again like the other one): I am trying to take command line arguments and pass them to the WinApi GUI. My code is here, the problem is that the MessageBox function requires const char * whereas while trying to get the actual message from the command line I need a char * (to run strcpy())
I have read about converting const char * to char * stackoverflow.com/questions/25549562/… but is also says it's a bad idea. So I don't know how to solve the problem. Could anyone suggest some way around the problem?
@Simon well, it should segfault anyways. arg is not allocated in Your code. And You're trying to overwrite it with each argv.
So const char arg;
Also is const char *argv[] OK in main(), - I thought of this myself so I am dubious?
@Simon that would be a single character allocated statically.
@Simon that is the way described in the standard.
So I need to set a range... something like const char arg[20];
@Simon well, You can do that. And please, use strncpy() instead then.
15:58
Ok. Sorry. I have been told to do that before.
Oh I forgot the error: dpaste.com/1X4HA4Z
16:14
@Simon What you are doing don't make sense
send full code
@Simon no ! NEVER DO THAT
"You could use strdup() for this, but read the small print. Or you can of course create your own version if it's not there on your platform.

And the question remains: Why do you need a char*, can't you change your code so that it works with const char*?"
That is my complete code :(
Perhaps an updated version is in order: dpaste.com/31GTY85
@Stargateur If you mean never use strdup() that is why I am here. Because I did read the small print...
no use strdup
bu WHY do you have a const char *
correct main proto is int main(int argc, char **argv)
From the docs: msdn.microsoft.com/en-us/library/windows/desktop/… the argument is LPCTSTR
"LPCTSTR"
sorry don't understand a thing with microsoft shit
from stackoverflow.com/questions/321413/lpcstr-lpctstr-and-lptstr LPCSTR is a const string LPCSTR: constant null-terminated string of CHAR (Long Pointer)
16:20
so there's no problem
char* is trivially convertible to const char*
@Stargateur I'm the same. Really easy to remember LPCSTR but there is no point complaining...
I think I understand what you want to do
@milleniumbug if you are after the error dpaste.com/00E3E8W.
@Stargateur I want to take command line arguments. For example: Message Hello World (where Message is the name of my program). I want to display Hello World but minus the Message part.
I did get it working with just MessageBox(NULL, argv[1], NULL, MB_OK); but that only does one argument. I need to take any amount.
16:30
@Simon this code makes no sense
that is, this line strncpy(arg, argv[i], strlen(argv));
@Simon that what I understand
strlen gets you the length of a string. argv is not a string
If you ask me all the string primitives in C standard library are garbage and I wouldn't use them here
I can't see an alternative though.
sum the length of all the strings, add one to account for null character, allocate this much memory (see malloc), use a nested loop to copy
or use glib vOv
Sorry, got to go. I will be back later
16:41
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>

int main(int argc, char **argv) {
    char *str = malloc(1);
    if (!str) {
        return EXIT_FAILURE;
    }
    *str = '\0';
    size_t i = 0;
    if (*argv) {
        while (*++argv) {
            size_t j = strlen(*argv);
            char *tmp = realloc(str, i + j + 1);
            if (!tmp) {
                free(str);
                return EXIT_FAILURE;
            }
            str = tmp;
            strcpy(str + i, *argv);
didn't test it, but should work
17:20
Just pasting here in case anyone has insight.
17:41
I'm back...
@Stargateur It works :) . Thanks, I still have to learn how you did it though. What is the longhand way of while (*++argv) {? I'm not sure what this does.
It means, "while the next pointer in arg vector isn't null"
1. Increment argv.
@Micrified you get really better in C ^^
2. Dereference the incremented argv to get the pointer to the argument.
You could write:
Wait I'm not so sure that helps.
for (char **ap = argv + 1; *ap != NULL; ap++) { ... }
@Simon If you don't understand my code you should read a C book, and yes I could write it for "readable" but I always make it hard to read to force people to understand the code that we give to them instead of just copy past it ;)
You could also interpret it is: while ( *(argv = argv + 1) != NULL) { ... }
Ultimately it's most concise the way Stargateur put it.
The reason he most likely pre-increments is because the first argument of the vector is the program name. You usually don't care about that.
17:52
@Stargateur I am not saying, nor suggesting, you should write it any different. I am saying I don't understand what you wrote in places, and would like some more information (actually I prefer it if I can't just copy and paste it without actually understanding it)... Still going through it at the moment.
@Micrified Thanks very much. I understand now. :D
18:06
I think I was just served a cup of water from the coffee machine/pad.
I can't taste any coffee at all. WTF.
This sh*t isn't cheap either.
You know what also irritates me?
I'm in the kitchen making this stupid coffee, and I know one of my roommates is in the bathroom doing their business (not the short kind).
I am standing between their path to the washroom to wash their hands.
They never went to it. -_-
haha * 2
I'm not a cleanliness freak, but that is downright unhygienic.
I know exactly who it is too. Notorious for this stuff.
And while I'm on that topic, I can't wait to see this place after I leave.
It's going to be a trash-dump. I can guarantee that.
In public space it's indeed a hygienic problem
18:15
I was up until last month providing free hand soap in the bathrooms.
The nice push bottle type.
And now I won't do it anymore.
Because this same ****** uses it as body wash.
I found it in the shower twice.
And it went from full to empty in 10 days.
Which is way too fast for normal lifetime.
this is a very annoying house mate
Yes. He is a junkie/stoner type of person.
 
3 hours later…
I wouldn't bother updating if I were you. It looks new enough. :D
Actually don't you will down-grade from 10.1.1.44 to 10.1.1.40
21:33
not my photo ;)
I noticed the site, nice find.
^^, but that off topic ;)
Such a shame. That really brightened my day. :(
Suppose I protect a piece of memory (p) with PROT_NONE (no reading, or writing). Somewhere along the way, I perform the operation:
*p = 1
I am definitely attempting a Write. Does that also contain a Read though, given I am asking for *p.
Suppose I have signal handlers setup for SIGSEGV.
Which condition will I violate first?
And suppose I grant Read/Write permissions only depending on the reason for the signal. Will I receive a second consecutive signal once the other operation is performed (I don't know the order)?
21:50
I suppose it's write because it wouldn't make sense if not
e.g. Bad_Read -> Grant Read ... Bad_Write -> Grant Write, Ok.
vs
Bad_Write -> Grant Write ... Bad Read -> Grant Read, Ok.
I have fucking no idea ^^
ask to linus
I want to base some functionality off this. This is giving me bad vibes.
Like a OS dependent race condition.
22:43
> You use global without reason
> You don't initialize hints instead you affect it.
> You use global without reason
> You don't verify all your system call error !
> You use global without reason

« first day (1423 days earlier)      last day (2433 days later) »