« first day (743 days earlier)      last day (4222 days later) » 

12:00 AM
@LucDanton Ah. I don't think you can use alignas to make a looser alignment (not sure if it's forbidden or ignored), so you can't simulated packed with it.
@LucDanton Yeah, I played a bit loose with syntax. :S
 
decltype(foo::x) should be valid C++11, IIRC.
or maybe only sizeof was fixed that way?
 
What I meant is that you can observe it by finding an object with an x member on an address that is not a multiple of alignof(decltype(x)).
> The combined effect of all alignment-specifiers in a declaration shall not specify an alignment that is less strict than the alignment that would be required for the entity being declared if all alignment-specifiers were omitted (including those in other declarations).
Yeah, ill-formed to alignas(1) int x; on common implementations.
 
hmm
how do I set an application to start up with Windoze?
 
I know there are about three and a half metric tons of ways of doing that. I have no idea which is preferred.
There's a Startup folder on the Start menu where you can put shortcuts that are run on login.
 
it's OK, I already revised that design five times
 
12:06 AM
I see. I think the Standardese way to express what you intended is static_assert( alignof(foo::x) >= alignof(decltype(foo::x)), "Oh noez" );. IIRC Standardese doesn't make use of 'multiples'.
 
There are also three or four or five or a hundred registry keys where you can register for that.
 
Because objects with different alignments than their types are already expected via alignas.
 
@LucDanton Ah, so alignof(foo::x) is actually valid (no object required)?
 
@R.MartinhoFernandes I haven't checked, but it should be. It queries the member, not an object, not a type.
 
@LucDanton With a packed struct you would observe <.
 
12:08 AM
@R.MartinhoFernandes Yep. Difference alone doesn't cut it.
So not an attribute after all?
 
@LucDanton Nope.
 
@R.MartinhoFernandes Should be like sizeof (and decltype, I think) and make that valid.
 
> error: ISO C++ does not allow 'alignof' with a non-type
I guess I'm checking then.
 
> The operand shall be a type-id representing a complete object type or an array thereof or a reference to a complete object type.
 
12:11 AM
alignof(decltype(foo::x))?
 
@DeadMG But that is always equal to alignof(decltype(foo::x)).
 
Not the semantics we would have wanted, because special alignment annotations won't carry over to the type.
 
um, no shit?
@LucDanton ah ok
 
@DeadMG Look at the assertion.
 
oh, I think I got it
 
12:12 AM
alignas(std::max_align_t) int i; has type int still.
 
you just phrased it confusingly
I was like, "Dafuq? You look like one of those ... C++ compilers."
 
Fuck, what does alignas even operate on.
> the assignment-expression shall be an integral constant expression
Okay then, now to express the maximum alignment in an ICE.
 
assignment?
 
> When the alignment-specifier is of the form alignas( type-id ), it shall have the same effect as alignas(alignof(type-id ))
Whoops, two paragraphs.
@R.MartinhoFernandes Grammar.
 
It would have to be a runtime assertion then? But I don't think there's a "is this aligned?" function.
One could use the dreaded std::align if it guarantees it doesn't touch already aligned pointers.
 
user142019
12:15 AM
Geocoder gem y u default to miles not kilometers kilometers are used by the entire world y u stupid and y u use miles.
 
Wut? No it's fine. The assignment-expression is what goes in the alignas(/* here */).
> alignof(std::max_align_t)
From the Standard Itself.
 
OK, so that's the second thread this week that I wish I'd never started:(
 
@LucDanton But how do you express the alignment of the member?
@MartinJames What's the problem?
It's just a bunch of standard geeks looking at a mildly interesting curiosity.
 
No problem really - I got the answer I wanted, then an extended discussion of alignment sorta exploded..
 
@R.MartinhoFernandes Ah right. Ignore the bit about alignas though. That was for my own benefit.
 
12:19 AM
Hello.
 
I don't think it's possible to query it. Alignment values are 'magic' right? Can't construe anything from the result of alignof(foo) and offsetof(x, foo) I would think.
 
T test_dummy;
void* ptr = &test_dummy.x;
std::size_t space = sizeof(test_dummy.x);
assert(std::align(alignof(decltype(test_dummy.x)), sizeof(test_dummy.x), ptr, space));
I think this would be enough to detect it: the assertion triggers when it finds a packed member.
I had to look up std::align's signature again. That thing is so wrong.
 
Hah, so std::align is the tool to check alignments against addresses then?
 
Basically, if ptr is not properly aligned for the type of x, std::align cannot align that pointer because it was given the exact size of x as space; it returns a null pointer on failure.
 
No wonder I've needed and reimplemented that thing. I don't need to think too much about alignment.
 
12:25 AM
Ok, I'm going to sleep now. Tomorrow I need to double check that I have everything packed and shit. Good night.
 
night scrubcake
I am off to eat a meal with relatives
 
Hey
is it ok if I ask a C question?
 
yes
 
this being a C++ place I figured you guys wouldn't object
char ** lines = (char **)malloc(sizeof(char *) * 100 * 100);
I want to read in a file into a char[1000][1000]
so basically just lines of text
and then sort them by the first letter of each line
I want to do it dynamically but whenevr I try to index into that array I get a segfault
or a thread bad access exception
 
Are you allocating the rows?
 
12:31 AM
FILE * file;
char ** lines = (char **)malloc(sizeof(char *) * 100 * 100);
char ** ptr = lines;
char c;
int row = 0, col = 0;
file = fopen(argv[1], "r");

if (file) {
while ((c = getc(file)) != EOF) {
if (c == '\n') {
col = 0;
printf("%s\n", ptr[row]);
row++;
continue;
}
*ptr[row] = c;
}
}
sorry that's ugly
 
You have to allocate the rows
and don't use magic numbers
char** lines = malloc(sizeof(char*) * 1000);
for(int i = 0; i < 1000; ++i)
  lines[i] = malloc(sizeof(char) * 1000);
Understood?
 
yes, thank you so much
the hours I have wasted
 
100 * 100 isn't 1000. Ah I get it!
 
@Dave Do you understand why he did that though?
 
so I mallc
 
12:35 AM
error checking is annoying though
 
You need to allocate space for pointers to each row, and then allocate each row
 
if the inner fails make sure you break and free the lines
 
I malloc'd free space equivalent to the entire file, but I forgot to malloc each row. so lines will contain an array of pointers who will all point to actual arrays of chars, but this memory will not be contiguous.
 
it is not equivalent to the file it is equivalent to 1000 char*
which is why you shouldn't use magic numbers
 
yes you are right
but pubby, there is no way for my program to know how much space is in the file is there?
 
12:37 AM
Yes, the memory is not contiguous. If you want contiguous memory you can malloc a single array of 1000 * 1000 chars, and then index into it appropriately
 
you want to use realloc and expand the size while reading
meaning you count lines as you read the file
you can use lookahead for the rows instead of realloc
 
woa, genius, im not sure how to do that safely
Praetoria, like this? double **dmatrix(size_t m, size_t n) {

double ** ptr1 = (double **)malloc(sizeof(double *) * m * n);
double * ptr2 = (double *)malloc(sizeof(double) * m);

int i;
for (i = 0; i < n; i++){
ptr1[i] = ptr2+m*i;
}


return ptr1;
}
 
using C++ would make it a lot easier to do it safely
 
that is contiguous no?
yea, using the CLR would make it very safe
but I need to learn my roots
 
you got the dimensions backwards
double ** ptr1 = (double **)malloc(sizeof(double *) * columns);
double * ptr2 = (double *)malloc(sizeof(double) * rows * columns);
Or maybe that should be rows for ptr1 I dunno
 
12:40 AM
char *lines = malloc( 1000 * 1000 );
// instead of lines[i][j] use
lines[i + j * 1000] = whatever;
 
Did I put the wrong template parameter in template <typename T> class Lounge or what?
 
I think I got the indexing right, but that may not be possible when you're reading a file
 
if you are going to be sorting rows you probably want a malloc per line though
 
I see, so I fixed my other solution too
 
@Pubby oh yeah, that's true
 
12:41 AM
double ***d3darr(size_t l, size_t m, size_t n){

double *** ptr1 = (double ***)malloc(sizeof(double **) * l);
double ** ptr2 = (double **)malloc(sizeof(double *) * l * n);
double * ptr3 = (double *)malloc(sizeof(double) * l * n * m);

int i, j;
for (i = 0; i < l; ++i) {
ptr1[i] = ptr2+m*n*i;
for (j = 0; j < l; ++j){
ptr2[i] = ptr3+j*n;
}
}

return ptr1;
}
 
Actually, not a malloc, just a char**
 
and then to print it f = d3darr(sizeof(l), sizeof(m), sizeof(n));
printf("%s %d\n", "The total number of bytes allocated was: ", m * n * l);
for (i=0;i<n*m*l;++i) {
printf("%p - %d\n ", (void *)&f[i], i + 1);
}
0x7f931a4038c0 - 1
0x7f931a4038c8 - 2
0x7f931a4038d0 - 3
0x7f931a4038d8 - 4
0x7f931a4038e0 - 5
0x7f931a4038e8 - 6
0x7f931a4038f0 - 7
0x7f931a4038f8 - 8
does that mean its contiguous
 
You allocate way too many things.
 
:)
 
@Dave Don't cast the return value of malloc. And T*** can usually be avoided
 
12:42 AM
the compiler issues me a warning if I don't cast
 
You don't need to maintain separate arrays of pointer, i.e. views into the contiguous array.
 
p8.c:20: warning: format '%p' expects type 'void *', but argument 2 has type 'double ***'
 
user142019
y u use malloc and void*
 
What's your compiler?
 
user142019
Use RAII.
 
12:43 AM
gcc
C89
old school
 
user142019
Oh C.
 
What's your command line invocation?
 
i use gcc -ansi -Wall -pedantic p1.c -o p1
is that what you mean?
 
Yes.
 
ok, but back to the d3arr, is the way i printed the memory correct? I see it increment by 1 byte
 
12:46 AM
Oh, that warning is correct. Anyway, the original comment was to not cast the return value of malloc. Nothing to do with printf.
 
ohhh
wait why? I heard that is proper
 
It's harmful in C.
 
good to know
ok, now back to the file read
 
136
A: Do I cast the result of malloc?

unwindYou don't cast the result, since: It is unnecessary, as void * is automatically and safely promoted to any other pointer type in this case. It can hide an error, if you forgot to include <stdlib.h>. This can cause crashes, in the worst case. It adds clutter to the code, casts are not very...

 
woa interesting, I had some people force me to cast malloc
 
12:49 AM
@Dave well, you need to if you're going to compile that code as C++
 
I see
 
otherwise, it's not necessary
 
ah k good
can I ask you another question?
so now that I have mallocd stuff dynamically
I want to alphabetize based on first letter
void alphabetize(char *text[], int nlines) {
int i, j;

for (i = 0; i < nlines; ++i)
{
for (j = 0; i < nlines; ++j)
{
if (tolower(*text[i]) > tolower(*text[j])) {
swap(&text[i], &text[j]);
}
}
}
}
I'm going to compare the ascii values
 
Now that you have switched to a contiguous piece of memory char* text[] has to be adjusted.
 
and avoid capitalization by converting to lower
how so
oh, i
I'm sorry luc, in the file read code, contiguous is not a requirement
but I'd like to know how to do that to
Can i just switch the values of the pointers to swap lines?
 
user142019
12:53 AM
@Dave You can edit messages by hitting the up arrow on your keyboard. See the newbie hints.
 
thanks
void swap(char ** a, char ** b){
_______ char * temp = *a;
_______ *a = *b;
_______*b = temp;
}
is that legal
 
user142019
Also, indent code by four spaces so it won’t look so crappy.
 
It's not a matter of the requirements, the issue is that the declaration must match the memory you have allocated.
 
user142019
Especially when it’s C, which is designed to be unreadable.
 
@Dave That swaps pointers. Whether that means swapping a line depends on what constitutes 'a line'.
Define precisely what is your data and the operations will follow.
 
user142019
12:56 AM
 
user142019
@Dave ^ third button.
 
user142019
Because unindented and improperly indented code (which includes GNU-style code) are unreadable as hell.
 
the data is as follows:
David Johnson
John Doe
George Sullivan

Those values will be read into an array of char[][]. The first character of the first line will be compared against the first character of the second line. If its ascii value is greater than the first, a swap will occur of the pointer that points to that line
 
Just hit control-k
 
Ohhh thank you
 
12:58 AM
char[][] suggests arrays with static sizes, not dynamic allocation. Could be just me though.
 
char ** lines;
my bad you're right
 
user142019
C-style arrays and pointers are terrible.
 
void print_lines(char **, int);
void swap(char **, char **);
void alphabetize(char *[], int);

int main(int argc, char **argv){
    FILE * file;

    char ** lines = malloc(sizeof(char*) * 1000);
    for(int i = 0; i < 1000; ++i) lines[i] = malloc(sizeof(char) * 1000);

    char c;

    int row = 0, col = 0;
    file = fopen(argv[1], "r");
    if (file) {
        while ((c = getc(file)) != EOF) {
            if (c == '\n') {
                col = 0;
                printf("%s\n", lines[row]);
                row++;
there is the whole shebang
 
That suggests a line is char* -- so yes, your swap did in fact swap lines.
 
user142019
@Dave You have a resource leak since you never close the file.
 

« first day (743 days earlier)      last day (4222 days later) »