« first day (531 days earlier)      last day (4415 days later) » 

user457812
11:00 PM
Also, are you aiming for C89 or C99 or some other probably now esoteric version?
 
Why am I getting this?
render.cpp:107:11: error: stray ‘\342’ in program
render.cpp:107:11: error: stray ‘\200’ in program
render.cpp:107:11: error: stray ‘\213’ in program
I don't have any stray characters :(
 
@Pubby are you on windows?
 
@Pubby unicode, invisible?
 
No
I don't think so
 
@Pubby try your favourite editor (vi?) to give your source the same encoding you compiler prefers. (utf-8)
 
11:04 PM
@MooingDuck So I changed it to ideone.com/Vv7IK but I get 'all_tracks_p' undeclared (first use in this function) but clearly I created the pointer.
 
Hmm, now it works after retyping
 
@LearningC I don't get that error, but your fscanfs make absolutely no sense at all
oh, now I get that error.
 
hmm, map of the game so far?
 
14 mins ago, by nil
Because it's probably undeclared in that scope?
 
@MooingDuck my fscanfs worked.
 
11:05 PM
section1 anyways :P
 
user457812
This code doesn't make any sense..
 
@LearningC all_tracks_p is inside of a for loop
 
user457812
I don't think all_tracks_p even needs to exist
 
@nil doesn't seem to. You're right that this code makes no sense
 
@MooingDuck Want me to post the whole code?
 
11:07 PM
@Hoxieboy are you obeying physics? Chicken
@LearningC no, I already found your problem. Well, I found three+ problems.
 
user457812
@LearningC Why is tracks_title an int *?
 
@nil a pointer
 
@LearningC a pointer to integers?
 
@MooingDuck yes
 
@LearningC which you scanf("%[^\n]s") into?
 
user457812
11:08 PM
@LearningC No, why is it an int pointer?
 
@LearningC turn your warnings up/on (compile with -Wall) AND PAY ATTENTION TO WHAT IT SAYS
@LearningC: but the heart of your problem is that all_tracks_p is in a scope (for loop), and the line printf("%d",all_tracks_p.playlist_hits); is outside that scope. So the variable doesn't exist anymore.
 
@MooingDuck so I can't return all_tracks_p either?
 
@LearningC since I assume that is your intent, simply declare it to be outside the for loop if you want it to exist outside the for loop.
@LearningC think of it this way: Anything created after a { is destroyed at the corresponding }.
for(int i=0; i<size; ++i) { //open a new scope
    void* variable = NULL;
} //matching close bracket, scope is destroyed
 
@MooingDuck Let say I constructed a structure in the for loop, with it's size and everything. I can no longer access it from another function?
 
@LearningC correct, it was destroyed.
@LearningC unless you used malloc
 
user457812
11:14 PM
Yerp.
 
which I did
 
user457812
You used it for one thing, the track title, and you used it incorrectly in some sense
 
@LearningC all_tracks_p was not created in malloc'd memory.
all_tracks_p is a local variable, on the stack, and is destroyed at the matching }.
 
user457812
It's also a useless variable anyway.
 
user457812
Also, what is going on with this format string: "%[^\n]s"?
 
11:18 PM
@nil true
@nil no idea, but GCC seems to accept it.
 
can I give you guys my whole code?
 
@nil assuming regex it reads characters that aren't newlines?
@LearningC why would you do that? This code has plenty of problems as it is
 
@MooingDuck but somehow it is doing what I want =)
 
user457812
Pretty sure scanf doesn't take a regex
 
(I might be getting a little ornry. I don't get to see my girlfriend today, and I have to wake early tomorrow for the dentist) :(
 
11:20 PM
except for returning the structure array
 
@LearningC it doesn't even compile, I doubt it does what you want
 
user457812
Is this for homework?
 
this is my project.
 
user457812
Is your project homework?
 
@nil yes
 
11:20 PM
Spent 10 hours on it and so far im 5% done =(
Mine is compiling.
It is basically taking a file and parsing the tacks on it
 
@LearningC oh, if you fixed the code, then yeah, we'll want an update
 
no didn't fix it fully, just the part that reads in information.
 
Your two scanf lines still make no sense.
namely, scanf(filething, " ", since scanf usually ignores spaces anyways.
then you pass that a parameter for some reason, which it completely ignores.
 
@MooingDuck that one is to get rid of the space
 
@LearningC scanf ignores spaces, doesn't it?
 
11:23 PM
this is fscanf
 
cplusplus.com/reference/clibrary/cstdio/fscanf: "the function will read and ignore any whitespace characters (this includes blank spaces and the newline and tab characters) which are encountered before the next non-whitespace character. This includes any quantity of whitespace characters, or none."
 
fscanf(album_file, "%[^\n]s", all_tracks[i].tracks_title); this is to stop scanning until it reaches the \n
let me show you the results
 
@LearningC those two lines do the exact same thing as fscanf(album_file,"%s", all_tracks[i].tracks_title);
 
@MooingDuck will it stop at the "\n"?
 
@LearningC If you say it works, I believe you. That doesn't mean it makes sense.
@LearningC yes
 
user457812
11:25 PM
@LearningC I don't think scanf works with regex stuff like that, and scanf stops on \n anyway, so all you're doing is giving it an invalid format string (though I'm baffled that it even worked).
 
@MooingDuck so since all the data will be destroyed there is no way I can pass all_tracks to another function?
 
user457812
You could if it wasn't allocated on the stack as it is now.
 
@LearningC correct. You'll have to malloc it to get it to exist outside the function scope.
 
user457812
Basically, you'd want to allocate it like (album *)calloc(number_of_albums, sizeof(album)) for allocation (or use malloc) instead of declaring it as you are now.
 
does fscanf with "%s" not have a way to say "read at most N characters" where N is a variable? How strange!
 
user457812
11:28 PM
I was actually looking for that because I could've sworn it would've had something like strncat
 
user457812
Found jack all, so I guess scanf is just as godawful as ever
 
@nil (album *)calloc(number_of_albums, sizeof(album)) so I use this it malloc an array?
 
@LearningC yes
 
user457812
@LearningC FYI, you might want to hit up man malloc for documentation on malloc, calloc, and its other abominable cousins
 
user457812
I just like that it zeroes the allocated chunk of memory.
 
11:42 PM
@nil that's pretty sweet
 
user457812
Yeah, though really you should just be using C++
 
@nil he can't. homework. You should see the libraries he has to use
 
Hmm... come to think of it. I'm not quite sure that new in C++ can do everything that malloc() can in C.
*legally that is...
 
user457812
I'd say it's still probably better (for most purposes).
 
@Mysticial what do you mean? Only drawback I knew of was no realloc
 
11:50 PM
Yeah, I know. but here's a corner case I can think of
suppose I want a buffer that I want to reuse multiple times with multiple datatypes
The only valid type for it is void
which only malloc() can do.
any other type will violate strict aliasing.
Is there a way to allocate a void* in C++?
 
user457812
I have memory pool stuff implemented in C just because it's easier to cram it into everything else if it's C to start with.
 
user457812
There probably is, but it's probably not advisable.
 
@Mysticial char*?
 
@MooingDuck It's legal to alias any datatype with char. But not the other way around.
 
@Mysticial char* (and unsigned char*) are specified to be aligned for all types just for that reason
@Mysticial wait what? typedef thing char;?
 
11:54 PM
@MooingDuck Um... no, they aren't always aligned. It's pretty easy to break the alignment.
*legally in C/C++, break alignment with char
 
@Mysticial new char[1] is aligned for all types, if I recall, same with unsigned char. (signed char doesn't have that guarantee)
 
that's why the exception for strict-aliasing with char is only one way.
 
C++11 § 5.3.4/10 "For arrays of char and unsigned char, the difference between the result of the new-expression and the address returned by the allocation function shall be an integral multiple of the strictest fundamental alignment requirement (3.11) of any object type whose size is no greater than the size of the array being created."
[ Note: Because allocation functions are assumed to return pointers to storage that is appropriately aligned for objects of any type with fundamental alignment, this constraint on array allocation overhead permits the common idiom of allocating character arrays into which objects of other types will later be placed. —end note ]
 
Oh, so it only applies to the pointer returned by new
I was talking about this case:
unsigned char buffer[5];
int val = *(int*)&(buffer + 1);
 
@Mysticial yeah, not members or automatic or anything
 
11:57 PM
that will break alignment...
 
6 mins ago, by Mysticial
which only malloc() can do.
no you weren't :D
 
guess you were right. :)
 
@Mysticial WOOOO! I GOT ONE
 
Now the question is
 
@Mysticial you're right that I should have specified that only applies with new expressions, not all arrays of char
 
11:58 PM
Is it still undefined behavior to cast that char* to another data type?
since it technically still violates strict-aliasing
or is there an exception for new?
 

« first day (531 days earlier)      last day (4415 days later) »