[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 27
File: solution.png (14 KB, 851x330) Image search: [Google]
solution.png
14 KB, 851x330
Old thread - >>51686086
>>
>>51689650
Jesus fuck.
>>
Daily reminder that comments and formatting slow down compilation

Single spaces are all the whitespace you need
>>
>>51689650
http://pastebin.com/JTPXTzjt
>>
Threadly reminder that arrays of C strings are literally, LITERALLY impossible.
>>
Code of Conduct:
- No traps
- No gays
- No fedoras
>>
File: kate upton tits high test.jpg (859 KB, 2953x1899) Image search: [Google]
kate upton tits high test.jpg
859 KB, 2953x1899
>>51689538
please help
>>
>>51689719
you're passing a std::string*[8] to a function that takes std::string*
>>
File: high test swim girls.jpg (174 KB, 540x810) Image search: [Google]
high test swim girls.jpg
174 KB, 540x810
>>51689740
it gives me a segmentation fault if i take out the [8] though
>>
>>51689650
i want to barf
>>
>>51686783
Why not run an svn server on your personal server that would just mirror all the requests to the secure one?
>>
>>51689785
start over

>>51689658
>>51689802
>>51689675
>>
>>51689650
Daily reminder that 8 lines of C string handling can be done in one clear line of Julia.
>>
File: 1449275429017.png (67 KB, 851x330) Image search: [Google]
1449275429017.png
67 KB, 851x330
>>51689650
>>
>>51689693

Define "string"
Define "array"
>>
>>51689847
Not again
>>
>>51689826
Daily reminder that Julia runs like molasses compared to C.
>>
>>51689650
Losing my shit having to port this horrible VBA code to C++. Deep nested uncommented VBA code that gets stealth updated overnight by some shit coder and I have to reflect the updates in the C++ program.
Don't ask me why we're still updating the VBA when we've ported the program to C++ a while ago; I didn't make these decisions.
The latest and greatest code just erased yesterday's work because somebody decided they actually didn't want to calculate the value the way they were doing it. Fuck these people, man.
>>
>choice of language doesn't matter, algorithms and data structures matter
How deluded are these faggots?

Show me a 3D game written in Python.
>>
this fucking guy
>>51689869
>>
>>51689650
does anyone here have an idea of FLEX? My uni wants us to create a lexical analyser (is that how you say it in english?) for PYTHON using FLEX. I have no fucking clue what to do.
>>
>>51689912
Just do it, go ahead and point it out.
>>
>>51689819
don't say that, please help i posted the code
>>
>>51689826

Yes, and Julia's interpreter is written in C and C++, and a number of its standard libraries are written in C and Fortran.
>>
>>51689847
julia> Int64[1:10;] |> a->map(string, a)
10-element Array{ASCIIString,1}:
"1"
"2"
"3"
"4"
"5"
"6"
"7"
"8"
"9"
"10"
>>
>>51689914
lexical analyser sounds about right
you could also call it a lexer but that's not proper English
>>
guys join my chat-room in PHP
http://tymko.2fh.co/blab80/blab80/blab.php
>>
>>51689910
https://wiki.python.org/moin/PythonGames
There are a fuckton. Writing a 3D game in python is stupid, but don't argue against it like that.
>>
>>51689890
Let's see the code big guy

When I write it, it runs fast than most people's C.
>>
>>51689938
i aint clicking that
>>
>>51689952
its fine i promise :^)
>>
>>51689936
that was the least of my worries to be honest but thanks
>>
>>51689947
OK, can you show me your code first?
>>
>>51689947
For you, maybe. Do you feel like your code is efficient?
>>
>>51689946
>all of them use libraries written in C

This doesn't count.
>>
>>51689976
def main:
run wolfram3d.exe;

see its two lines of python code but it runs just as fast as the c version
>>
>>51689998
:^)
>>
>>51689929
What's your point? No one's saying something can't be done in C, just that it's unnecessarily low level, like assembly language at this point.
>>
File: 1393685184718.png (32 KB, 150x190) Image search: [Google]
1393685184718.png
32 KB, 150x190
>>51690005
Is this the level of programmer the current generation is producing?
>>
>>51689976
I don't know much about this shit but since Python is interpreted I'm pretty sure it's literally impossible to do anything 3D without using a wrapper for a library of a different language. I could say something about goalposts but I have a strong hatred for kids that learn python and want to make gayms.
>>
>>51689964
My code of what? You said Julia runs like molasses.

>>51689970
I pay attention to heap allocations and cache locality while optimizing with SIMD vectorization in ISPC, not to mention architecting for lock free concurrency, so yeah, I think I know what efficiency is.
>>
>>51690050
Was leaking memory a part of your design?
>>
>>51690032
That's reality, sorry Ctard. C++ makes C obsolete except for niche architectures. Don't mistake me for someone rationalizing only being able to use Ruby or some bullshit.
>>
>>51690050
http://julialang.org/benchmarks/
The scale is shit but what can you expect from Julia-shills :^)
>>
>>51690076
C isn't really lower-level than C++, it just doesn't provide as much syntactic sugar.
>>
>>51690076
>except for niche architectures
name one
>>
>>51690067
What are you even talking about.
>>
I know there is negligibly little documentation or comments now but could I get some help with this? The Heap Allocator Page Faults whenever I kfree(). http://neetco.de/ZenosCave/BamfOS
>>
>>51690101
You don't get to ask questions.
>>
>>51690005
How unnecessary is it if it's still being used in spite of the "better" high level alternatives...?

I sincerely doubt someone created julia out of spite and chose to use C out of spite.

Come on, Anon. Go back to /b/.
>>
>>51690096
I think some features of C++ make it a little more high level, even if such features are just syntactical sugar. Deconstructors, new and delete come to mind.
>>
File: cisshit.png (10 KB, 914x224) Image search: [Google]
cisshit.png
10 KB, 914x224
>>51690043
Why is C such a shitty language?
>>
>>51690131
pebcak.
>>
>>51690131
this

i just wanted to add two fucking pointers
>>
>>51690131
holy shit anon
>>
File: tegaki.png (4 KB, 400x400) Image search: [Google]
tegaki.png
4 KB, 400x400
>>51690130
Maybe a better way to say it is that C is no lower level than C++, while C++ still provides higher level features if you want.
>>
>>51690128
Woman, you aren't helping shit.
>>
>>51690155
Exactly, yeah.
>>
>>51690131
haha
>>
>>51690131
puts("Hello " "World");
>>
>>51690128
Time for your Schizophrenia meds I think.
>>
>>51690173
How does that work? That's not a string concatenation.
>>
>>51690128
>>51690178
Perhaps he's wondering why you would delete a pointer before exiting the process
>>
>>51690129
It does seem to work well as a compiler target.
>>
Anyone else hate std::ostream::operator>> and std::istream::operator<<? Stupidest shit ever. Can I just use printf in C++?
>>
>>51689693
umm...
char *arr[32][64];
/* an array of 32 char arrays of 64 characters each */
>>
>>51690220
yeah you can
>>
>>51690098
Cypress PSoC
>>
>>51690220
Yes.
>>
>>51690220
I don't. Extraction and insertion make reading and writing trivial.
>>
>>51690225
That's not a string, anon. You can't concatenate them with the "+" operator.
>>
>>51690225
no
>>
>>51690238
strcat
>>
What does the /g/ think of the code in general? >>51690114
>>
>>51690232
http://www.mbedded.ninja/programming/microcontrollers/psoc/using-cplusplus-with-psoc-creator
>>
>>51690244
>C tards confirmed for not reading
>What is the "+" operator
>>
>>51690238
do you even know how your sandboxed toy scripting language does that?
it strcats both strings together into a new string and returns the output.
>>
>>51690225
NOT REAL XDDDDDDDDDDD
FIXED SIZE XDDDDDDD
AND IF YOU REPLY WITH AN EXAMPLE USING THE HEAP
YOU DID SOMETHING WRONG BUT WE WONT SAY WHAT
XDDDDDDDDDDDD

>>51690229
>>51690233
Noice. I mean I know that I always can, just if it was taboo.
>>51690235
"The extraction operator", as one book put it. I find it horrible having typed printf etc calls a load of times.
printf("number: %d times\n", num);
//vs
std::cout << "number: " << num << " times\n";


>>51690244
he was being facetious, don't worry
>>
>>51690268
Are you fucking with me? Even Java has a + operator that can concat strings and it runs on JNI so don't give me that bullshit. C is just a shitty language, period.
>>
>>51690269
cout looks cleaner and more readable here.
>>
>>51690269
>>51690220
the cool kids don't like seeing you do it tho, fyi
>>
you guys sure love your retarded circlejerk

it's always the same shit
>>
>>51690269
did you mean to write that all in one post?
stupid frogposter
>>
>>51690283
C is a bare-boned language, not a shitty one. Java is C with training wheels that makes you wear a retard helmet so you can't hurt yourself
>>
File: 1434747963728.png (73 KB, 200x209) Image search: [Google]
1434747963728.png
73 KB, 200x209
>>51690298
>Circlejerk
We all hate each other and disagree on everything.
>>
Why doesn't this work?
int array[2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2];
>>
>>51690285
>here
>the most basic example
It's purely preference.

>>51690291
Yeah, I know.

>>51690302
Did you need to screenshot it? Yes I did intend to do that. Two seperate conversations, doesn't bother me if I'm a sperg in one and not the other.
>>
File: disgusted feel frog.jpg (85 KB, 454x453) Image search: [Google]
disgusted feel frog.jpg
85 KB, 454x453
>>51690302
>not using tomorrow
>>
>>51690320
I've no idea anon.
>>
>>51690322
Don't reply to my posts again.
>>
a string can be a dependent type
the type depends on the length

e.g. a vector or array of char

a string of mutable length can't exist directly on the stack
a string of immutable length can
>>
>>51690320
>>
>>51690322
The most basic example isn't really a fair comparison anyway. Extraction and insertion really shine when handling streams.
>>
>>51690342
Good post
>>
>>51690145
In what world do you live in where this makes sense to do?
>>
>>51690341
Sure thing anon.

>>51690347
I don't know; I get rather uncomfortable when I see a bunch of << or >>'s, but long format strings or multiple calls to input functions don't bother me. Just what I'm accustomed to.

>>51690366
Java land.
>>
>>51690320
That's like 20 dimensions, which would mean a million elements at 4 bytes each, adding up to around 4 MB.

I think you're overflowing the stack with that.
>>
>>51690374
Explain why you would ever have a legitimate need to add 2 pointers together?
>>
File: 1416118772628.png (364 KB, 411x411) Image search: [Google]
1416118772628.png
364 KB, 411x411
>>51689650
> tab_width = 8
Fucking barbaric
>>
>>51690366
char* x = malloc(500*sizeof(char));
//some code that uses a lot of memory, then is supposed to free it
char* y = malloc(500*sizeof(char));
printf(y - x);
>>
>>51690386
>He doesn't know the machine king from the Matrix shit posts in dpt
>>
>>51690404
That's not adding two pointers.
>>
File: sizeof.png (87 KB, 808x573) Image search: [Google]
sizeof.png
87 KB, 808x573
>>51690404
>>
>>51690392
Not him, and I can't think of a reason to add, but my heap allocator subtracts two pointers often.
>>
>>51690386
>He doesn't have 4MB of RAM
Holy fuck.
>>
>>51690420
wrong screenshot, I wanted to post the "you wouldn't size of a char" one.
>>
>>51690428
>>51690404

>subtraction is the same as addition
C-tards are this deluded.
>>
>>51690420
>>51690443

portability to C++
in C++ unsigned char is guaranteed to be 1 byte, but I don't think char is necessarily
>>
>>51690392
I (the anon you responded to) am not him; I was poking fun at Java users.
>>
>>51690269
Jesus man wouldn't it be easier to just not use C?

Why put yourself through all this pain?
>>
>>51690204
At least you can run. What are you?
>>
>>51690453
a - b ≡ a + (-b)
>>
>>51690456
sizeof (char) in C++ is 1
even then, C++ would require casting to (char *)
>>
>>51690456
Why wouldn't it be? UTF-8 is still 1 byte signed.
>>
>>51690480
Who said that real number algebra commutes to pointers?
>>
>>51690467
What pain? Format strings aren't half bad.
>>
Nobody here knows shit about programming, they just like to regurgitate syntax and semantics.

I bet they couldn't even write a strrev function in idiomatic C.
>>
>>51689675

system("pause");


0/10
>>
>>51690556
sorry, should've been

loop:
if (max > min)
goto loop;
>>
>>51689604

this I have not texted, but, it looks on par with what you gave me

#define MAX_ENTITES 768

typedef struct
{
double startX;
double startY;
int prototype;
boolean used;
} entity;

entity g_ENT[ MAX_ENTITES ];

void g_ENT_updateall (void)
{
int i;

for ( i=0; i<highest_used_entity; ++i )
{
if ( g_ENT[i].used == false )
continue;

lua_pushnumber(vm, g_ENT[i].prototype);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the prototype table
lua_pushstring(vm, "update");
lua_gettable(vm, -1); // get the update method
lua_pushlightuserdata(vm, g_ENT + i);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the data table
lua_pcall(vm, 1, 0, 0); // call the update method
}
}

void g_ENT_drawall (void)
{
int i;

for ( i=0; i<highest_used_entity; ++i )
{
if ( g_ENT[i].used == false )
continue;

lua_pushnumber(vm, g_ENT[i].prototype);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the prototype table
lua_pushstring(vm, "draw");
lua_gettable(vm, -1); // get the update method
lua_pushlightuserdata(vm, g_ENT + i);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the data table
lua_pcall(vm, 1, 0, 0); // call the update method
}
}

void g_ENT_add ( int obj )
{
int entity = highest_used_entity;

int prototype = obj;

g_ENT[ entity ].prototype = prototype;

lua_pushlightuserdata(vm, g_ENT + new);
lua_pushnumber(vm, prototype);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the prototype table
lua_pushstring(vm, "new");
lua_gettable(vm, -1); // get the constructor
lua_pcall(vm, 0, 1, 0); // call the constructor
lua_settable(vm, LUA_REGISTRYINDEX); // register the data table with the entity's address

highest_used_entity++;
}

void g_ENT_remove ( int entity )
{
g_ENT[entity] = g_ENT[highest_used_entity];
--highest_used_entity;
}


does that seem correct to you?
>>
>>51690597
Thank you for convincing me to avoid Lua.
>>
>>51690597
Why do you still have "startX" and "startY"?

Also
lua_pushlightuserdata(vm, g_ENT + new);

should be
lua_pushlightuserdata(vm, g_ENT + entity);


And what's with passing in "obj" but then simply turning it into "prototype"? Just pass in "prototype" directly...
>>
File: 1444950610574.png (99 KB, 340x340) Image search: [Google]
1444950610574.png
99 KB, 340x340
what the fuck happened in this thread
>>
sup guys, learning python as a first language, any tips for a newbie like me?
>>
>>51690632
No catposters are present, so the thread is shit
>>
>>51690392
Dirty hacks: a struct with a void pointer which references multiple kinds of data (what kind exactly is given by an enum). You can also store an integer value in a void pointer, and you might want to add that value to something.

You can of course cast a pointer to a long long, add, then cast back.
>>
>>51690634
You'll learn more by programming than asking for tips on /g/
>>
>>51690634
>python
>>>/b/
>>
File: 38621452_p0_master1200.jpg (603 KB, 768x768) Image search: [Google]
38621452_p0_master1200.jpg
603 KB, 768x768
Should I start learning C?
>>
Rate my strrev implementation.
void strrev(char *input, char *target) 
{
/* if both arrays aren't equal length,
and the target is on the stack, it's the user's problem */
const unsigned len = strlen(input);
unsigned t_len = strlen(target);
if (len != t_len)
target = (char *) realloc(sizeof(char) * len);
int i = len - 1;
int j = 0;
while (j < len)
{
*(target+j) = *(input+i);
j++;
i--;
}
}
>>
>>51690675
yes
best thing I ever did.
>>
>>51690675
dude please delete that image, i'm at work and almost got fired
my boss is a fellow 4channer and redditor and he lets me browse as long as it's SFW, but your pic is not only NSFW and violating the rules of this board, but could probably be borderline illegal. I'm gonna have to clear my chaced data to delete that thumbnail and inspect element to block your picture.
>>
>>51689693
If a string is just an array of bytes, and arrays are just sequences of bytes, then aren't all strings just strings of smaller strings?
>>
>>51690675
yes i recommend "The C++ Programming Language" by bjarne stroustrap
C is a subset of C++

-bjarne
>>
>>51690711
>casting
>*(...+n) instead of ...[n]
>sizeof (char)
>no size_t
>no const char
0/10
>>
File: 1422948562497.jpg (79 KB, 1280x720) Image search: [Google]
1422948562497.jpg
79 KB, 1280x720
How do you make an array of arrays of strings in C?
>>
>>51690711
Why the fuck would you put the resizing logic in there? Should be entirely the caller's responsibility, and is one reason why C can be faster than almost anything else since you're not doing potentially wasteful validation or "massaging".
>>
>>51690724
I am so sorry :(
>>
>>51690711
>strlen
>>
>>51690745
You use the
``''
operator.
Example:
int main(int argc, char ** argv)
{
char *** c = ``"Frob 1"''"Frob 2"''"Frob 3"'';
puts(c);
}
>>
>>51690748
>potentially wasteful
it's a comparison
holy shit it's 2015
a single instruction doesn't hog the whole CPU anymore
>>
>>51690790
Why are you using C if you're just going to write code like a fucking animal?
>>
>>51690784
What the fuck
Is this real?
Link to standard? Can't really google for ``''.
>>
>>51690711
>
sizeof(char)


dude
>>
>>51690801
/g/ is really my favorite board, thanks Anon
>>
string characterCode[256];

what are the strings in this initially? i only want to print the strings in an array spot if it's been changed after initialization
>>
>>51690816
readability

>>51690804
symbolhound
>>
>>51690804
Yeah, it was only added in c11 though so you might have to mess with the compile options in GCC to get it to work. MSVC certainly won't support it because they forked from C89.
>>
argv is an array of strings :|
>>
>>51690801
Why would you write library code that is incredibly easy to break?

>>51690816
looks much better than 1 * len
plus, it visually reinforces that i'm creating a char array.
>>
>>51690835
>>51690854

It's "readability" to include a statement that will always result to 1 as part of a MULTIPLICATION statement?
>>
>>51690835
>readability
use sizeof *target instead.
>>
>>51690866
Yes.
It's to benefit the reader.
The compiler doesn't give a shit, it's converted to 1 at compile time.
>>
>>51690850
No, argv is a null-terminated array of null-terminated arrays of unterminated bytes.
>>
>no dick sucking qt trap in thread op

Why even bother? You cant program without that.
>>
>>51690824
I'm serious, though.

>>51690854
Why would you write library code in C while not trusting the user at all? You still have the restriction that if the strings aren't of equal length, the target has to be malloc'd.

Java might be more your speed if you think that library code has to be "soft" and waste time because of the assumption that the caller is a retard.

A proper language would have a type system that allows you to quantify the requirements in the code, but that's another tale for another time.
>>
>>51690846
I always use C11 so that's no problem, thanks

>>51690835
Thanks.
>>
>>51690885
why would you need to multiply a number by one, though
>>
>>51690891
if it's a null terminated array of null terminated strings, why is it passed the size of the array
>>
Why does dpt never discuss low level graphics programming?
>>
>>51690913
It isn't, it's passed the location of the byte you want in relation to the location of the first byte that you don't want.
>>
>>51690833
please respond
>>
>>51690900
>You still have the restriction that if the strings aren't of equal length, the target has to be malloc'd.
So it'll throw a compiler error.
The only real reason it's there is to throw a compiler error because i'm sure most users would put the string buffer on the stack anyway.
>>
>>51690895
just for you
>>
>>51690833
What lang?
If this is C, it isn't filled with anything.
>>
>>51690931
What? No it won't.
>>
>>51690912
why not?
who the fuck uses malloc to make an array using only a single number?
>>
>>51690944
sorry, it's c++
>>
>>51690926
I'd love to.
>>
>>51690955
see >>51690882
>>
>>51690926
>graphics
>low level
>>
>>51690955
>why not
you'd save that many bytes in your source code by not having it, because multiplying any number by one is mathematically irrelevant

>>51690963
Then all you did was define it, not initialize it, and when you try to read from that array you'll just find garbage data left over from whatever program was running in that spot in memory prior to yours.
>>
>>51690976
Are you implying graphics programming can't be low level? What the fuck man.
>>
>>51690984
t. Sanjay "i've never written anything more substantial than a fizzbuzz" Gupta
>>
>>51690984
how do i initialize it to be null?
>>
>>51690984
>you'd save that many bytes in your source code
>>51689661
>>
>>51690833
The empty string.
>>
>>51690320
You have 38 dimensions.
2^38 = 274877906944 int allocated in stack.
274877906944 * 4 bytes = 1 TB.

Do you have 1TB memory?

I didn't do this to prove anyone wrong, it was just curiosity to see how much memory that would use.
>>
>>51690833

if that's supposed to be C++, I believe it calls the default constructor to fill the array.
>>
>>51691024
based page filing
>>
>>51690926
I know all about it (in terms of OpenGL at least) but most people here are just beginners
>>
>>51691042
>OpenGL
>low level
pfhah
>>
>>51691026
>>51691019
so i would just test if its length is greater than 0?
>>
>>51691061
Explain to me in 50 words or less how VBOs are not low level.
>>
>>51690984
>Then all you did was define it, not initialize it

C++ will use the default constructor to fill the array. Try this sample:

#include <iostream>

class Test {
public:
Test() { std::cout << "Test constructor.\n"; }
};

int main()
{
Test test[50];
return 0;
}
>>
>>51691061
Shaders can be pretty low level
>>
>>51691081
holy shit i was just baiting but really
a buffer is low level to you
fucking hell
>>
#include <iostream>
using namespace std;
void main(void);void:void;//void
{
//program to get age of user and return that age in days

cout << "Please enter your age in years: " << flush;
string s = "\0";
cin.getline(s,256);
cout << "Your age in days is: " << sizeof(long long) << endl;
}


r8
>>
>>51691067
Sure.

>>51691081
They're low-level enough since they correspond directly to GPU memory, but most of OpenGL is incredibly abstracted away from what's actually happening.

>>51691095
Shaders are another example of something that is still pretty low-level.

>>51691096
Fuck off, you're not me.
>>
>>51691096
Well? I'm waiting.
>>
>>51691067
Yeah, or call empty()
>>
>>51691106
>Fuck off, you're not me.
He's not but you're not me either though
>>
>>51691106
no, i was >>51690976
>>
>>51691124
You know monitors and GPUs are hardware right anon?
>>
>>51690745
pointer to pointer to pointer
>>
File: hw.png (28 KB, 715x618) Image search: [Google]
hw.png
28 KB, 715x618
>>51690550
#include <stdio.h>

void strrev(char* c)
{
int len = 0;
while(c[++len]);
while(len--)
{
char temp = *c;
*c = c[len];
c++[len--] = temp;
}
}

int main(void)
{
char* s = "Hello world!";
strrev(s);
printf("%s", s);
}

Do I pass?
>>
trace.cpp: In function ‘void printCodeArray(std::string*)’:
trace.cpp:106:36: error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string<char>}’ through ‘...’
printf(": %s\n", characterCode[i]);

what do i do? i'm using #include <string> and trying to print the string to standard output
>>
>>51690631
>Why do you still have "startX" and "startY"?
I just haven't removed it yet

>what's with passing in "obj" but then simply turning it into "prototype"?
I hadn't changed the syntax yet when I working on it

void g_ENT_add ( int prototype ) 
{
int entity = highest_used_entity;

g_ENT[ entity ].prototype = prototype;

lua_pushlightuserdata(vm, g_ENT + entity);
lua_pushnumber(vm, prototype);
lua_gettable(vm, LUA_REGISTRYINDEX); // get the prototype table
lua_pushstring(vm, "new");
lua_gettable(vm, -1); // get the constructor
lua_pcall(vm, 0, 1, 0); // call the constructor
lua_settable(vm, LUA_REGISTRYINDEX); // register the data table with the entity's address

highest_used_entity++;
}


but I will try it out in a bit when I have a chance to compile and run it
>>
>>51691151

Either use cout (which can use overloaded << operator with std::string) or call the c_str() function on characterCode[i] to get a C-string.
>>
>>51691151
The c function ``printf'' takes a char**, not a string. It's really not advisable to try and use c functions in c++ programs.
>>
>>51691185
>>51691191
std::string x = "tbhfam";
x.c_str(); // a null terminated char* of x


ignore the guy saying don't use c functions
>>
What exactly is function overloading?
Does it mean I can use the same function name to describe 2 separate functions depending on the number of arguments?


eg.
a strrev function that reverses in place and only takes 1 argument
a second strrev function that takes 2 arguments that copies the contents of the first string into the second string in reverse order
>>
>>51691211
Yes, and also type of arguments. Like a strrev that takes a string, and a strrev that takes a string + an int (number of characters to reverse maybe?), and a strrev that takes a string + a buffer
>>
File: compressed character codes.png (38 KB, 544x779) Image search: [Google]
compressed character codes.png
38 KB, 544x779
>>51691209
ty i used this solution
>>51691185
>>51691191
ty also

will this compress a text file enough for it to be worthwhile? this is the first compression program i've written
>>
>>51691211
>Does it mean I can use the same function name to describe 2 separate func tions depending on the number of arguments?

Yes, but oftentimes it depends on the type of argument and not just the number.

For example a function that takes an int will be different than a function that takes a string even if they have the same name.
>>
>>51691211

you have two functions with the same name but that take different parameters

the compiler selects which function you call based on the types of the parameters you pass
>>
>>51691211
Overloading is declaring multiple things of the same name yes. You can declare multiple functions of the same name but different types in some circumstances.
>>
>>51691234

What are you using? Huffman codes?
>>
>/dpt/
>nobody can program competently
>everyone can rattle off definitions (essentially, just trivia) immediately
>>
I'm new to graphics and I have to pick an API for a basic 2d game written in C++. I'm gonna make a blackjack game cuz I'm a lazy fuck.

I don't know anything about APIs. What would be a good one to use for just the basic tasks of drawing 52 dickish little rectangles with shapes and numbers in them? Someone else said SDL but I thought I'd ask for a second opinion. Some options mentioned in the layout:

SFML, Qt, Windows Forms, SDL, Allegro, DirectX, & OpenGL.
>>
>>51691267
yes
>>
>>51691271
Use SFML for easy mode
>>
>>51691271
For a card game, you'll be more than fine with Qt or WinForms.
>>
File: science fan.jpg (104 KB, 504x533) Image search: [Google]
science fan.jpg
104 KB, 504x533
>>51691269

Everyone on this board is the guy on the left but tries really hard to pretend to be the guy on the right. Fortunately, it's not as bad as /sci/.
>>
>>51691294
>>>/reddit/
>>
>>51691271

I'd use SDL.
>>
>>51691304
Enjoy your slowness.
>>
What's your opinion on Rust?
>>
>>51691271
I picked up SDL in about a week, was easy flying from there. You should have no problem with it.
>>
>>51691294
why is the science fan depicted as an old man in professional wear, and the scientist depicted as a 20 year old in a black tshirt
>>
#include <iostream>
using namespace std;
main()
{
cout << "Please enter your age in years: " << flush;
signed char c;
cin >> c;
cout << "Your age in days is: " << sizeof(sizeof(unsigned long long int)) << endl;
if(c) goto d;
if(sizeof(char)-1)
{
d: return sizeof(unsigned char);
}
return 0;
}


I made it better.
>>
>>51691312
Advertised as a paragon of safety but it's not, at all. It's almost no better than modern C++ with move semantics.
>>
>>51691271
SFML is the simplest
>>
>>51691294
So we pretend not to know?
>>
>>51691318
because it was made by a 20 year old science fan
>>
File: nigger.png (37 KB, 737x404) Image search: [Google]
nigger.png
37 KB, 737x404
>>51691211
Here is and example.
>>
>>51691338
>1.0f
>not 1.f
enjoy your slow compile time
>>
>>51691271
WinForms should be by far the easiest
You can't have smooth animations in WinForms without advanced techniques though
>>
>>51691338
>char pause;
>std::cin>>pause;
just get a terminal emulator please
either install loonix or get cygwin
>>
File: nig.png (20 KB, 731x597) Image search: [Google]
nig.png
20 KB, 731x597
>>51691360
>Tfw still waiting for the program to compile to this day
>>
>>51691338
If you just want to pause at the end for testing purposes, ``system("pause")'' would be preferable.
>>
>>51691408
troll
>>
>>51691338
$ gcc -std=c11 -o fuck fuck.c 
fuck.c:9:8: error: conflicting types for ‘test’
double test(double a)
^
fuck.c:3:5: note: previous definition of ‘test’ was here
int test(int a)
^
>>
>>51691420
I compiled that with g++. I did mention circumstances.
>>
>>51691420
C doesn't have function overloading like C++ does.
>>
C11 GENERICS
AHAHAHAHA SO PATHETIC
>>
NEW THREAD

>>51691509
>>
>>51691517
70 posts away
DELETE THIS
>>
>>51690037
Much of python uses external binary libraries with c style linking (no matter what they're actually written in). Open a window on the desktop, draw a triangle, run a FFT over data, open a socket: at some level ALL of those use an ecternal compiled library. Even some of Python's core functionality works like that. So it really can be fast enough to run games, but often as glue, or higher level logic, and not the heavy lifting.
>>
>>51691543
>python fags
>we wuz useful
>>
>>51691307

Is SDL notoriously slow? I've never had a problem with it. What's wrong with it?
>>
>>51691543
That's pretty much what I was trying to say, yeah.
>>
>>51691568
I've had some problems with it, but if you aren't retarded you're fine.
(It lagged when I had it rendering everything in the world, and not just what was visible from the camera. Smooth as ever when I fixed that. But, the world wasn't that big to start with.)
>>
>>51691267
no news i good news i hope?
>>
>>51689675
This makes me feel better. It's too long and too consistent to be a mistake. It wasn't an idiot's CS 101 project. Someone competent wrote a program to generate that source automatically.
>>
I tried writing SDL and it would freak out about double-freeing upon exiting.
>>
>>51691603
Someone asked /dpt/ to help with his assignment to find the min and max of 10 numbers.

I did this
>>
>>51691517
Kill yourslef.
>>
>>51691619
With a script or copy and pasting?
>>
>>51691673
Get a load of this mad tranny ;)
>>
>>51691697
The first version (small part of it is pic in OP) was copy/paste/replace in notepad. It was buggy so I automated it in D.
>>
so we are learning R at school

does that have real world application? could i potentially use that in a business or would they be like, "that is some bootleg language, dude. we use matlab/python/whatever here."
>>
>>51691726
A lot of businesses use R actually. You're good.
>>
>>51691427
> I compiled that with g++.
It doesn't matter whether you use gcc or g++. The file extension is .c so it's compiled as C. Rename the file to have an extension of .cc, .cpp, .cxx or .c++, or use "-x c++" to override the language detection.
>>
File: 1443461691306.jpg (25 KB, 302x302) Image search: [Google]
1443461691306.jpg
25 KB, 302x302
XAML-bros, where does this guy get the "ApplicationResources" key in his answer? How does he add a key to Application.Resources (I suppose)?

http://stackoverflow.com/questions/6156154/mvvm-light-viewmodellocator-resourcedictionaries

This is annoying, I don't have enough reputation to comment and he was last active in 2014 anyway. Have been looking for answer for some time now.
>>
>>51691753
No actually the file extension is cpp. I don't think I'm the person you think I am.
Thread replies: 255
Thread images: 27

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.