« first day (520 days earlier)      last day (3116 days later) » 

2:42 AM
@Doorknob mhm... how does the string differ from any other byte sequence?
hint: difference is really tiny.
also, those functions intended to be used for memory buffers. Mostly dealing with strings. Also, those do have wchar_t counterparts, e.g. wmemset, wmemcpy, wmemmove, etc
 
3:09 AM
@Kamiccolo Sure, they're null terminated, but I still want to move memory that doesn't happen to be a string...
Or is it because the amount of memory to move is measured in chars?
 
@Doorknob my point is, that this kind of lack of distinction is mostly historical... :)
 
So, memmove was originally created only for strings, and they never bothered to move it out of string.h? :P
 
back then it wasn't such a big difference between character and byte.
@Doorknob and move it where? :}
 
3:54 AM
@Kamiccolo uhh, stdlib.h, I guess?
stdlib has all the memory allocation-related functions anyway (malloc, free, realloc, etc)
 
 
5 hours later…
9:10 AM
@PeterVaro It was already in my watchlist, your recommendation has made it climb some positions.
 
 
3 hours later…
11:47 AM
@deckard :)
 
 
2 hours later…
1:54 PM
@Doorknob those are more generic and less related to characters than to how memory is managed in one or another Operating System. To back my claim, last comment
 
@Doorknob Technically even today, a C byte is a character by definition
BTW, malloc/free/realloc/calloc are about allocated memory, so I don't think that grouping them together, is necessarily a better idea
The only thing the rationale has to say about string.h: the general goal was to provide equivalent capabilities for three types of byte sequences: null terminated, null-terminated with a specified length, and 'transparent data' with a specified length
 
3:15 PM
Hello!
 
helloc @EProgrammerNotFound; // :}
 
I have heard of a term: COM Heap, do you guys knows what it means?
I believe it's too basic for a question
I don't find anything about it... everytime I type COM heap on google it shows me heap and stack. Nothing specifically related to COM
The idea is that a WideString is the same as a BSTR. Because a BSTR is allocated on the shared COM heap then it is no problem to allocate in one module and deallocate in a different module.
--> Because a BSTR is allocated on the shared COM heap then it is no problem to allocate in one module and deallocate in a different module.
Nevermind I've just created a room to ask David Hefferman himself about it
 
3:30 PM
@EProgrammerNotFound sadly, not that familiar with Windows and COM objects.. I hope, You'll be able to solve that :}
 
4:10 PM
helloc all
 
i have a code which working good
but i need to do it dynamic
so i used malloc and now code is giving run time error
how can i find where is the problem?
i did some debug but it didnt help much
 
@Emredağıstan have you ever heard of valgrind?
because that's exactly the tool you are looking for!
(but ofc you can use gdb and lldb and stepping line-by-line (or breakpoint-to-breakpoint) in your code while it is being executed)
(also: a some printfing can always save your arse ;))
for example:
puts("01");
some_call();
puts("02");
other_call();
puts("03");
if some_call() fails, only 01\n will be printed, however if other_call() fails 01\n02\n will be printed and if everything goes fine, you will get 01\n02\n03\n
 
ok i will try this
 
if you found out where the problem is, you can dig deeper, and start printing this method inside the function which produces the error
@Emredağıstan but I still highly recommend you valgrind, it is Free and Open Source, very easy to use and very very accurate
it saves you plenty of time
(also you can use some static-analyzers -- even if some errors could only be produced at runtime, static-analyzers could do wonders)
helloc @Haris;
 
4:21 PM
@PeterVaro helloc;
 
@Emredağıstan If you have a reasonable code sample, feel free to paste it to a service such as codepad.org or ideone.com
 
links allowed here?
 
@Emredağıstan even full code snippets if you promise you will use the multiline formatting ;)
 
codepad.org/oFStfeIv so here is the code
this is masterpiece for me. :D
 
first of all: array=(int **) malloc(size*sizeof(int *)); <-- do not cast the return value of malloc
C will do the casting for you implicitly in this case
(this is not an error, just something that will reduce the code-complexity and redundancy)
also: always check the return value of malloc, calloc, realloc and aligned_alloc => they can return you a NULL which indicates allocation error
use size_t instead of plain int for defining the size and the indices of an array
double avgMean[howmanytimes]; <= this is only valid in C99 and in C11 if VLA is supported
(Variable Length Array)
okay, so, let's make things more simple for you: if I'm not msitaken, you want an array which holds integers (actually size number of integers), right?
 
4:41 PM
this is a grid
 
if that's the case, you should allocate size*sizeof(int) and then you can avoid the extra size times allocation, while you are allocating extra spaces for pointers to ints
@Emredağıstan I assume, you want a multidimensional array, right?
 
I'm searching for a canonical answer for that, but I could only find this:
26
A: Performance of 2-dimensional array vs 1-dimensional array

David ClaridgeIn C, 2-dimensional arrays are just a neat indexing scheme for 1-dimensional arrays. Just like with a 1D array, 2D arrays allocate a single block of contiguous memory, and the A[row][col] notation is just like saying A[row*NCOLS+col]. Usually if you were to implement your own multidimensional ar...

(which is not bad, but I'm still looking for the better answer posted a while ago on SO)
 
Can't you also implement arrays in C as e.g., int *array and then you array = malloc(sizeof(int)*rows); for (i = 0; i < rows; ++i) { array[i] = malloc(sizeof(int) * cols); } with the advantage being that while access and creation is slower, adding rows is much quicker? – derobert Aug 7 '09 at 3:56
@PeterVaro isn't same witm mine?
 
the truth is, you can allocate one huge space for your multidimensional array at once
and if you have only one pointer that is allocated
that means you only have to free one pointer as well
use separate allocations, if you want to realloc or free that memory space independently from the others
otherwise you don't need that
 
4:48 PM
let me say that
codepad.org/pwnI9niI this works perfect
 
let me write something for you, gimme a sec
@Emredağıstan I'm back, sorry I had to talk to one of my collegues :P
so:
#include <stdio.h>
#include <stdlib.h>

#define ROW_COUNT (size_t)3
#define COL_COUNT (size_t)5

int
main(void)
{
    size_t i,
           j;
    int   *array;

    if (!(array = malloc(sizeof(int)*ROW_COUNT*COL_COUNT)))
        return EXIT_FAILURE;

    for (i=0; i<ROW_COUNT; i++)
        for (j=0; j<COL_COUNT; j++)
            array[i + j] = rand();

    for (i=0; i<ROW_COUNT; i++)
        for (j=0; j<COL_COUNT; j++)
            printf("%d\n", array[i + j]);

    free(array);
    return EXIT_SUCCESS;
OUTPUT:
1804289383
424238335
1025202362
1350490027
783368690
424238335
1025202362
1350490027
783368690
1102520059
1025202362
1350490027
783368690
1102520059
2044897763
 
sorry im not goot at this :( what is array[i + j] ?
 
basically what I did here is simple: I've created a one dimensional array
I calculated the size as ROW_COUNT*COL_COUNT => just like a two dimensional array
now, follow the indices:
the value i will be 0..2, while value j will be 0..4
@Emredağıstan ahh, sorry my bad => the above code is not working as it should be
let me post the correct one, in a sec
 
5:10 PM
i suspected myself for a sec :D btw sorry you tired because of me thank you.
 
@Emredağıstan there you go:
#include <stdio.h>
#include <stdlib.h>

#define ROW_COUNT (size_t)3
#define COL_COUNT (size_t)5

int
main(void)
{
    size_t i,
           j;
    int   *array;

    if (!(array = malloc(sizeof(int)*ROW_COUNT*COL_COUNT)))
        return EXIT_FAILURE;

    for (i=0; i<ROW_COUNT; i++)
        for (j=0; j<COL_COUNT; j++)
            array[i*COL_COUNT + j] = rand();

    for (i=0; i<ROW_COUNT; i++)
        for (j=0; j<COL_COUNT; j++)
            printf("[%zu][%zu] = %d\n", i, j, array[i*COL_COUNT + j]);
@Emredağıstan it's not your fault really, I'm just leaving my workplace, and talking to collegues, while commiting on writing code for you :)
(ofc you can write more sane for-loops than this (more efficient I mean) I just wanted to illustrate my point here)
anyway, I have to leave my workplace => switching to mobile now :)
 
5:34 PM
so @Emredağıstan is it working?
 
[zu][zu] = 0
[zu][zu] = 0
[zu][zu] = 0
[zu][zu] = 0
[zu][zu] = 1
[zu][zu] = 1
[zu][zu] = 1
[zu][zu] = 1
[zu][zu] = 2
[zu][zu] = 2
[zu][zu] = 2
[zu][zu] = 2
 
user4651282
?
 
@PeterVaro Any purpose for casting the constants of ROW_COUNT/COL_COUNT?
 
@PeterVaro whenever x=0 or x=size-1 code crushes but why still looking for.
 
Hi folks this is cherub
 
5:41 PM
@DrorK. yepp, since C does not provide size_t literals, that's one way to write it as the compiler will optimize my cast
 
@PeterVaro But what purpose does it serve?
 
@DrorK. to prevent negative changes? Not sure, how it would react for (size_t)-1
 
@Kamiccolo it will be the maximum value size_t can be
 
@Emredağıstan Note that you use a for loop with k = 1, it's usually much easier to start from k = 0
 
@DrorK. well, the exact same purpose as 12UL
 
5:43 PM
@DrorK. yes but i dont think that is the problem
 
@PeterVaro Specifying UL can have a purpose when the type has significance, here it seems that there is none
 
in 2D array when assign first or last line, It crushes.
 
@Emredağıstan Feel free to share your updated code sample
 
@DrorK. I don't know.. I sleep well when I know my constants have the exact same size as I imagined :)
 
(which demonstrates the fault)
@PeterVaro Would you cast arguments to parameters which expect size_t?
@PeterVaro I dunno... malloc((size_t) 100); ?
Usually it's the other way around
You'd have to cast unsigned to signed, for avoiding warnings/diagnostics
 
5:49 PM
@DrorK. if those are "untyped" literals then I would
(I'm much slower on mobile, so sorry for delays)
 
The type of the constant is derived from its value and the implementation's native type ranges
@PeterVaro Would you cast a character constant? ... char c = (char) 'A';
 
wrong examples
'A' is literally the char literal
 
It's not
'A' is an int
 
yeah it is, but because of the literal the compiler knows it is
I mean you can write c=42 and c='whatever 42 is'
 
And you can write: malloc(100);
 
5:56 PM
while a number literal without decimal points will be an int
 
Well, you've mentioned that casting the return of malloc is redundant, I feel that casting integer constants, where the type serves no role, to be redundant just as well
 
@DrorK. printf("%zu", 12) -- is your compiler complaining?
(I bet mine does -- although I'm still on mobile)
 
I'm afraid my environment is a bit messy at the moment
 
let me check it.. my notebook is somewhere around..
 
There isn't an online service for one liners?
Found one, the type expected for 'zu' is size_t
This is an example of when you care for your types, va_args
At best I would cast the relevant constants when their type matters- and not as a blanket rule
I can think of only two occasions where you'd care for the type: va_args and bit-manipulation
 
6:01 PM
yepp -- I tested on my laptop => mine is comllaining
sure you can be "picky" --but I'm only casting otherwise untyped constants-- that's my "pick"
 
Most of the time you don't need to be picky, just as most of the time you won't need to cast pointers
People say that they choose to cast void pointers, for being 'consistent'
They tend to apply the same blanket-rule for parenthesizing 'sizeof'
 
yepp, similar
anywho, we should request ZU and zu as suffices for size_t for C17 ;)
 
codepad.org/i0SdBoN7 if you run the program and sign "size" "multiplier" you will see crush when row=0 or row=size-1; but why :'(
 
What do you mean 'sufficies'?
'suffices'? Oh, for integer constants?
 
yepp
(still on mobile and my typo is terrible today..)
*suffixes => I thought matrix=>matrices, then suffix=>suffices
anyway "wrongly typed" constant literal cast is not the same thing as the oarens rule for sizeof -- which I follow, as it makes my attempts more clear (not to mention how the standard states)
while using the cast in the abive case will help the compiler and will help the reader as well
(mm.. I'm feeling sick on this hot bus.. maybe I shoild stop writing/reading? ;))
 
6:18 PM
Why is it hot, what kind of weather do you have there?
 
it is hot, because they've turned on the heat -- btw the weather here is sweet, actually my favourite: a tiny bit chilly early automn night
 
@PeterVaro, are You familiar with Eigen library?
 
@Kamiccolo not really, sorry :(
why? worth using it?
 
@PeterVaro nah.... just their terminology have been pissing me off for... like... last two weeks. Just realized, that You were working with some 3D stuff.
Basically, geometrical representation, linear algebra, couple of libraries like Eigen and the code I've been staring at, in combination doesn't make much sense :|
@PeterVaro not sure, actually :D It supposed to wrap some linear algebra stuff for space transformation, etc.
Another thing which was pissing me off lately, lack of high-quality C related talks. And cancelled CConf :|
 
@Kamiccolo cancelled CConf? where?
@Kamiccolo hmm.. I see.. well, I'm sorry, but I cannot support your rant now :)
 
6:38 PM
@PeterVaro long story short, back in 2012-ties in San Diego community was organizing CConf. It supposed to be first C-only conference ever (?). Speakers and topics were lining up, but... apparently, it was cancelled because lack of speakers, difficulties of timing everything up and... unofficial reason - lack of finances.
sigh
 
oh fuck... I truly wanted to attend a conference like that.. or at least follow it on youtube..
that's super sad news..
 
Main organizer --- Brandon Philips with backing up from Linux Foundation...
 
anywho, bbl, I'm off now :)
goto walk_the_beast;
 
goto have_a_nervous_smoke;
 
@Kamiccolo // I'm also going to do that, just to support you emotionally :)
 
7:14 PM
helloc();
 
7:26 PM
these erratic bugs ll lead me someday to suicide, or atleast forget about programming and go sell popcorns in street
 
@Agawa001 sounds like a bright future :}
 
@Kamiccolo helloc(@Kamiccolo); //Criously, 3 days tracking the locality of this bug until i figured out that my processor got nuts
 
@Agawa001 heh, sounds like great fun :}
those cases then You're trying to find a bug in Your and Your colleagues' code and it appears to be... hardware issue... or BIOS upgrade issue... or whatever unrelated on the first glance... could drive anyone nuts and/or suicidal.
 
@Kamiccolo thats a Crious case, and psychologists must open a branch for this kind of psychosis
 
@Agawa001 it must be done :}
 
7:39 PM
many people can be deleberately terrorists when they spend lot of time on fictional bug
 
or lives are going to be wasted....
 
8:22 PM
people you might like this
0
A: Remove all occurrences of the first letter of a string from the entire string

Agawa001C(136) #define t(x)(x+32*(x>>5==2)) char*h(char*a,int b,int*c){char*v=a[b+1]?h(a,b+1,c):0;return(b<=*c)?v:&(a[b]=a[b-(*c+=t(*a)==t(a[b]))]);} Execution void main(){ char a[]="abac";int v=0; printf("%s",h((char*)a,0,&v)); return; } Output bc the function is recursive which i...

advice me how would it be jammed more
 

« first day (520 days earlier)      last day (3116 days later) »