« first day (229 days earlier)      last day (2615 days later) » 

6:07 AM
I was looking at answers for stackoverflow.com/questions/7666509/hash-function-for-string and all the answers give algorithms which take linear time with length of string to compute. Isn't that a disadvantage? Is there any other alternative? Just wondering, no real usage.
 
6:42 AM
1 message moved from Lounge<C++>
@user161151 If it doesn't scan over entire string, it's useless as a general-purpose hashing function
If you only hash the first 8 characters, then you'll get unacceptable performance when people use URLs as keys
https://hahahaha.you.wont.hash.this.com
hashed ^ not hashed
@user161151 And, in general, if you only hash over a part of the string, you risk DoS attacks on malicious input
 
7:42 AM
I am trying something
typedef struct PUBVAR_ENTRY_t
{
char name[32];
cell value;
}PUBVAR_ENTRY entries[] =
{
that code won't work for obvious reasons
I need PUBVAR_ENTRY and entries too
I can do it in separate line but idk why I like doing them together
 
typedef struct what is this, C?
 
I don't need the typedef
but the SDK uses typedef everywhere
so I am trying to maintain the style
 
@YashasSamaga because you want to create a maintenance nightmare probably
 
@YashasSamaga because it's necessary in C
 
7:44 AM
yea the SDK is in C
 
but it's totally not in C++
 
yea but if I don't use typedef, then my code will be using two different styles for declaring structs
 
yes and nobody cares
 
is this ugly?
struct { char name[32]; cell value; } entries[] =
{
 
7:51 AM
aw
as of now I don't use the struct anywhere else
 
also each entry in entries is of anonymous type now
 
?
got it
you meant the entries' datatype has no name?
 
struct Entry { /* whatever */ } entries[] = { /* initializers */ };
^ now each entry in entries is of type Entry
but then you aren't gaining much over
 
struct Entry { /* whatever */ }; Entry entries[] = { /* initializers */ }; so you might as well do that
 
7:54 AM
that increases the line even further
without improving anything
 
actually it does
 
huh? aren't the two pieces of code identical?
 
you aren't using an unreadable "declare a variable and a type at the same time"
my point is that you're wasting time on useless shit
 
:D
is using auto bad?
I use it everywhere for iterators
 
of course not
just make sure your IDE/text editor/whatever can tell you the type if you hover your mouse over auto
 
8:03 AM
yea it can
for (int i = 0, j = InterfaceList.size(); i < j; i++)
{
if (i == scriptKey) continue;
if (InterfaceList[i].empty()) continue;

InterfaceList[i].Trigger_OnScriptInit(scriptKey, InterfaceList[scriptKey].ScriptIdentifier);
}
is it reasonable to expect the compiler to convert the code to use pointers?
 
the only problem is when the deduced type is different than what you've expected
in which case you use an explicit type
@YashasSamaga there's nothing that would stop it, but if you want to actually be sure whether your compiler does that, there's only way to do it
and that is to check the generated assembly
 
my code is not in a compilable state atm :/
I modified an interface header, so the rest of the code won't compile until I make the changes
defeated the purpose of making interface lol
for (int i = 0, j = InterfaceList.size(); i < j; i++)
do I need to do i < j?
or can I do i < InterfaceList.size()?
and expect the compiler to do the work
I think size() gets inlined and the code added in place refers to the internal size variable
j = size() becomes redundant then
size_type size() const _NOEXCEPT
{ // return length of sequence
return (this->_Mylast() - this->_Myfirst());
}
hmm
so it isn't an internal variable
needs some calculations
 
8:32 AM
is this bad?
Interface::Interface::Initilize
I have a class Inteface inside the Interface namespace.
I have seen similar naming in the standard library too
if they do it, let me do it? :D
 
two-phase initialization is always bad
do what you're supposed to do in the constructor
 
I am reusing the objects
and I am creating fake objects too
if I place the code in the constructor, it'll do all unwanted things
 
otherwise I don't think you're forbidden from declaring a type with the same name as the namespace
 
9:05 AM
friend cell AMX_NATIVE_CALL ::Natives::ReinitilizeInterfaces(AMX* amx, cell* params);
IntelliSense is complaining about the ::Natives
it has issues with ::
namespace Interface { class Interface { public: friend cell AMX_NATIVE_CALL ::Natives::ReinitilizeInterfaces(AMX* amx, cell* params); }}
 
IntelliSense is one thing, your compiler is another
what does your compiler say
 
I can't compile :d
not because of that, my code isn't ready yet
 
9:31 AM
error C3083: 'Natives': the symbol to the left of a '::' must be a type
 
What do the :: at the left of Native mean? I've never seen that in c++
 
global scope
if I remove the ::, then I get
error C2653: 'Natives': is not a class or namespace name
 
What compiler are you using?
 
From this info I can only think Natives definition is not reachable, missing includes maybe.
 
9:39 AM
Natives is a namespace in the global scope inside interface.cpp
the class declaration is in interface.h
 
 
2 hours later…
11:19 AM
what is the overhead of creating local mt19937 objects
creating a million generators every second
 
 
1 hour later…
12:26 PM
@YashasSamaga don't
 
I create a generator each time an algorithm is called
:/
 
@YashasSamaga mt19937 is 2.5kB
 
yea so using a global object and seeding it on each call is useless as well
 
initializing that takes looooooooong
you may want to try pcg-random.org
It's small, fast and decent
and compatible with C++11 random API too
 
I thought Mersenne Twister was the most popular and most trusted RNG
that website says it has some failure
 
12:35 PM
randomness tests evolve
MT is good, and it's mature enough to be included in standard libraries
MT19937 was state of the art in 2001 or so
But it's probably overkill for your app
Also don't reseed so often
In fact, don't at all, unless you want to reproduce previously generated numbers
 
^
I need to store the state
or I have to make a cache
store random numbers
when asked to reseed, I'll just set the current index to zero
ah a problem
with one cache, I can allow one instance only
the code I am writing is for a game
each time a saved state is loaded, the same environment must be generated for each player (or a set of players)
there can be multiple levels
so I need to have more than one generator
or more than one cache
or kill the performance
random_device can throw exceptions, right?
what's going to happen if an exception gets thrown in the following case
random_dveice aaaa;
mt19937 bbbb(aaaa());
^ global scope
 
12:53 PM
your exception will not be caught, and your program will be aborted
unless you use a function-try-block with main()
in which case you can handle the exception, but most likely you will not be able to stop the program from ending
 
how would try-catch inside main catch exceptions which are outside main
random_dveice aaaa;
mt19937 bbbb(aaaa());
int main() { .... }
 
not try-catch
function-try-block
 
hmm leme google
 
that's int main() try { /* stuff */ } catch(...) { /* catch block */ }
 
never knew such a thing existed :|
aren't the constructors of global objects executed before main()?
 
12:58 PM
wait, I'm hilariously wrong
> function-try-block of the main() function does not catch the exceptions thrown from the constructors and destructors of static objects (except for the constructors of function-local statics).
 
static objects are as good as global objects, right?
so there is somethig which C++ is lacking
 
I usually don't use static/global objects so I don't mind
 
1:22 PM
that said, if function-try-block could catch static object constructors' exceptions, it would be 100% more useful
(by increasing the number of use cases from 1 to 2)
 
1:43 PM
Hey, is anyone familiar with std::thread? How can I run member functions with threads or pass this to the thread constructor to pass as an argument to a non-member function?
For example, if void run(MyClass* myclass) is a non-member function, how can I pass this to a thread constructor? mythread(run, this) doesn't work: error: no matching constructor for initialization of 'std::thread'
Anyone here familiar with std::thread?
How can I run member functions with threads or pass this to the thread constructor to pass as an argument to a non-member function?
For example, if `void run(MyClass* myclass)` is a non-member function, how can I pass this to a thread constructor? `mythread(run, this)` doesn't work: `error: no matching constructor for initialization of 'std::thread'`
 
in fact the example in this page is exactly that case (except they pass an int instead of a pointer)
 
Xeo
Show code or bust
 
user1804599
1:56 PM
"SSCCE or GTFO"
 
(ps: paste code elsewhere and post link here, dont paste code directly in chat, tia)
 
TIA?
 
10 messages moved from Lounge<C++>
 
I didn't know you could move messages to other chat rooms...
@milleniumbug Thanks for the link, it helped me realize that I forgot -std=c++11 in my compile command. I was not aware that the standard changed what was allowed for thread
 
Huh. Pre-c++11 there was no std::thread
 
2:00 PM
@sehe Ah... I see. Thanks for the help
@Borgleader Sorry, I can't seem to find a definition for TIA. What does it stand for?
 
"thanks in advance"
 
Got it
 
2:20 PM
OK I have another question now (kinda new to C++): How can I call a constructor from another constructor without the compiler thinking that I'm trying to cast the parameter? Relevant code pasted here
 
Also, wtf, don't read user input in a constructor
 
Fair enough
@milleniumbug I'm not sure I understand the requirements of a delegating constructor. Can I not call the other constructor at the end of the first one?
 
IIRC it's the same in Java, calling another constructor must be the first statement...
Took your advice: moved the getting-user-input elsewhere and just left the constructor with the port as argument. Thanks for all your help. Gotta go now.
 
user1593881
2:53 PM
In this question I see this: int (*arrPtr)[10] =... What is this int (*arrPtr)[10]? A cast, a temporary or am I missing something obvious?
 
user1593881
The (*arbitraryName) part is somewhat confusing to me.
 
user1593881
Is that the same as int* arrPtr?
 
~~the joy of C-style declarations~~
 
user1593881
Ah I see.
 
@RawN it's a declaration of a pointer to 10-element array of int
 
user1593881
2:57 PM
@milleniumbug Thanks. All clear now.
 
3:53 PM
cell(func)(AMX *amx, cell params[]) = (cell()(AMX *amx, cell params[]))(fid->address);
my static analysis tool is telling that I am doing a C-style cast
what would be the C++ equivalent?
std::function?
it even suggested static_cast but I guess that is a bug
 
Don't cast functions ever
 
V2005 C-style explicit type casting is utilized. Consider using: static_cast/const_cast/reinterpret_cast. functional.cpp 37
cell(*func)(AMX *amx, cell params[]) = (cell(*)(AMX *amx, cell params[]))(fid->address);
^ is the line
 
Hey
 
use fixed font or backticks
 
So...
In any give language that uses C-like syntax
 
3:56 PM
@YashasSamaga what is the type of fid->address
 
You'd have to parse the parameter lists of functions dependent of context, right?
Because they mean one thing in the declaration, and another thing when you're calling the function
Right?
 
@milleniumbug uint32_t
 
wut
why are you typecasting integers to function pointers
 
becaz I get the address from external source
and I use the same member to store other info
for functions in my code, it stores the address
for functions in the AMX machine, it stores the function index (id)
etc, etc.
 
let's hope you won't be porting to 64-bit...
 
4:00 PM
ye, that'd be a problem
the abstract machine supports 32bit only
so I'm fine for now
 
@EnnMichael no ambiguity in C wrt function declaration
int f(whatever); is always a function declaration
There is an ambiguity wrt AAA * BBB; though
you need to know all the relevant names beforehand
 
Well, int f(whatever); is always a function declaration, but f(whatever); is a function call
 
to distinguish between noop multiplication and a pointer to AAA declaration
 
Yes, I know
I think I may be missing what "Context Dependent" really means
Because isn't the function return type part of context?
If the parser sees the return type, it knows that the parameter list will contain new names (for the parameters)
But if it doesn't see a return type, it's a function calls, and the names already exist and refer to already existing variables
So, is that context dependence or not?
 
4:47 PM
Can anyone tell me why:
while (std::cin >> number) {
std::cout << number << std::endl;
}
produces strange behavious
if I have "6 4" as input with that code it only prints 4
but if I then input "6 4" again, it prints
6
4
as expected
 
SSCCE please
 
What is SSCCE?
 
@EnnMichael it would be difficult to write a pure context free C parser, which is why most of them aren't
 
something about your mom
 
@sweg_yolo_69 sscce.org
 
4:50 PM
@milleniumbug if there are strings that are very long, calculating the hash everytime could be pretty slow and performance could suffer, what can be done as an alternative?
 
@milleniumbug So basically I have to have two different manners in which I parse a parameter list
 
That's the whole code man:
#include <iostream>

int main() {
int number;
while (std::cin >> number) {
std::cout << number << std::endl;
}
}
first time I input "6 4" through STDIN I just get "4"
 
and plz indent it properly by pressing up and ctrl+k :)
 
but second time I do input that i get
6
4
 
@EnnMichael Or learn on their mistakes and don't make the declaration be similar to usage
 
4:54 PM
Well how would you define a function in mathematics?
 
write down every single possible input and pair it with the output
that's the basis behind writing any code
 
@milleniumbug Any thoughts?
 
Okay
But writing the parser itself is way more difficult than just writing inputs and outputs
And I have to come up with a sudo-language that is easy to parse
 
@user161151 several options: a.) ignore the problem b.) use faster hashing functions (still O(n)) c.) reduce the scope of your problem d.) don't recalculate the hash every time e.) don't use hash tables (IOW std::map instead of std::unordered_map)
@sweg_yolo_69 can't reproduce
 
@milleniumbug I guess it's a windows command line error or something
 
5:02 PM
@milleniumbug thanks for the answer.
 
How can I add an int to a char?
 
@milleniumbug By the way, can you even give me an example of a language that doesn't have the same declaration and use syntax for functions?
 
1 message moved from Lounge<C++>
@rockethon you don't
 
Haskell, python, C-like languages all have it
Rust too
 
what
 
5:10 PM
...What we talked about
 
def whatever(stuff): vs whatever(stuff)
yes, totally similar
 
Well... they are
Lol
 
what should I do then
 
do what
 
@milleniumbug This is an ironic message?
 
5:11 PM
yes, that's sarcasm
 
in order to get a number on a char varible
 
char stores a character
int stores an integral number
"how do I add a number and a character" well, you don't
 
so should I do it like c[1]='1' c being the char?
can I add the int to the char?
 
@milleniumbug Hey are we cool? What's up with you?
 
@EnnMichael I'm on mobile can't respond that fast
note that def keyword screams "TOTALLY A FUNCTION DECLARATION"
 
5:17 PM
I'm sorry I read too much into shit
 
@milleniumbug any tips
 
@rockethon your question makes no sense whatsoever
c[1] = '1' is totally not adding anything
 
Since I need a vector which is able to receive a number how should I do it?
@milleniumbug it was an example for you to know what I need to do
 
@rockethon do you want to convert a number into a string?
 
What's the best way to create a vector of ints from a getline() that reads input in the form of: "5 8 4 3 8 6"
 
5:22 PM
@milleniumbug yes
 
rockethon: i = 0; while (num > 0) { digit = num % 10; c[i++] = digit; num /= 10; }
 
21 hours ago, by milleniumbug
@sweg_yolo_69 read entire lines with std::getline, split the lines by using std::stringstream
 
can´t i use a simpler code
@milleniumbug
 
@rockethon std::stoi converts an integer to a string
so you think you will do conversions faster than developers of the standard library
that's... optimistic
 
5:52 PM
@milleniumbug how do I check if a vector has an element .at(i) without throwing an out of range exception
 
check if i is less than size of the vector
 
but can I do it it one line? For example:
if(i + 1 < vec.size() && vec.at(i) + vec.at(i +1) > 25)
if i+1 is bigger than the size of the vector, i get an out of range exception
do I have to do it like:
if(i +1 < vec.size())
if(vec.at(i) + vec.at(i +1) > 25)
 
6:30 PM
int operator=(uint32_t efid)
{
scriptKey = (0xFF000000 & efid) >> 24;
funcidx = (0xFFFF00 & efid) >> 8;
reserved = (0xFF & efid);
return *this;
}
what does that actually do?
I am confused b/w int a = object OR object = int a;
I might need to revisit my textbooks :/
 
6:59 PM
do people actually use vector<T>::iterator or are there usually preferred methods?
 
@sweg_yolo_69 this shouldn't happen, && short circuits, so the former is equivalent to the latter (if there's no else)
@YashasSamaga int operator= and return *this; together should not compile unless the class has an implicit conversion operator
 
operator uint32_t()
{
return (scriptKey << 24) + (funcidx << 8) + reserved;
}
I should actually be ORing those numbers
it doesn't matter though
 
@towc range-based for to avoid direct usage of iterators in the common case of iterating over a container, or auto to avoid verbosity when declaring such an iterator
 
7:32 PM
Interface *initilizing_interface = &InterfaceList[scriptKey];
is crashing my program
static std::vector <Interface> InterfaceList;
value of scriptKey is 0 which is correct
I am going to add a try catch
:o
catch fails to work
oh
AMX *target_amx = initilizing_interface->amx;
this is the line
I am guessing that initilizing_interface is not valid
huh the error isn't there, somewhere else
oh wth
can a pointer address be 0xCCCCCCCC
such a nice number
fixed, I had forgotten to initialize the amx member
 
8:42 PM
@YashasSamaga MSVC debug mode allocators are soooo nice
 
9:40 PM
hey, been a while since i went anywhere near C/C++, can somebody verify this for me? if i have a 2D double array double **input, if i want the length of the first dimension, is this correct? int inputArrayLength = sizeof(input) / sizeof(double *);
 
1 message moved from Lounge<C++>
@bizzehdee No
 
Ell
@bizzehdee you should have read the rules in that other room bub -.-
oh well
this room is good for questions
 
you can't deduce the size of an array from the pointer
 
Ell
@bizzehdee It's not correct
^
arrays aren't pointers
in c++ you want to use std::vector<double> (and pass dims manually), or boost::multi_array<double, 2> if you want something fancy
 

« first day (229 days earlier)      last day (2615 days later) »