-3

I have copied program on Simulated Annealing from a book (first result link here) and am facing the below issues on compilation, for below line in main().

srand48(tp.tv_usec);

Error on compiling with Dev-C++:

[Error] 'srand48' was not declared in this scope

The full code is at: https://onlinegdb.com/HyruMTmdN. & the relevant (trimmed version) is stated below:

#include <sys/time.h>

extern double drand48();
extern long lrand48(/*long*/);
extern int rand();
extern void srand(long seedval);



//main program
main()
{

//set random number generator
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp,&tzp);
srand48(tp.tv_usec);

return 1;    
}    
jiten
  • 193
  • 2
  • 10
  • Downvote not by me, but people here do not like questions which link instead of showing directly. Try to ask a question with all information right here and make a [mcve]. – Yunnosch Mar 23 '19 at 11:36
  • @Yunnosch Please see the sheer size of code, & the difficulty of choosing what all can be eliminated. – jiten Mar 23 '19 at 11:38
  • Try to reduce to code which only exhibits the first of the quoted errors. – Yunnosch Mar 23 '19 at 11:38
  • Alternatively, talk more about how you build. Many errors with otherwise successfully used code (i.e. libs, well-known tutorials...) arise from incorrectly building them. Is there a tutorial on building it? Is there a manual or at least a descriotion? – Yunnosch Mar 23 '19 at 11:40
  • @Yunnosch The book has no such details, & tried Sourcetrail to see the function call graph, but began pointing out first the error in math.h itself as shown at : https://i.stack.imgur.com/ZVAiu.png – jiten Mar 23 '19 at 11:50
  • 1
    I didn't downvote but you've effectively asked people to find code that's in a book and copied to another site (which, BTW, hangs on me, claiming to "check my browser" indefinitely without showing anything). Try going to the offending lines identified in the errors/warnings, expand the macros involved, then identify the types of variables and constants involved (e.g. `pop`, `x`, `pop[x]`).The errors/warnings you're getting indicate some pretty poor code though (or code using non-standard features from one compiler, being built with a compiler that doesn't support those features). – Peter Mar 23 '19 at 11:52
  • @Peter Please expand on your comment, & if possible make an answer; as would help me gain understanding of these issues better. – jiten Mar 23 '19 at 11:54
  • Not sure I can. Without code - which I can't see - it's harder to be more specific. The warnings are related to pointers to functions generally unable to be incremented (or have integers added to them) since they don't generally point to anything which behaves like an array. Comparing pointers and integers is akin to comparing your street address with the latitude of your bathroom sink - there is not enough information about the relationship between the two things to sensibly compare them – Peter Mar 23 '19 at 12:01
  • @Peter Have put the code in edited post. – jiten Mar 23 '19 at 12:17
  • Request to provide help as my code is not compiling, stucking my attempts to move further. – jiten Mar 24 '19 at 06:01
  • Did you read the man page? In particular, the necessary header file (``) and *Feature Test Macro Requirements*? – Toby Speight Mar 25 '19 at 17:57

1 Answers1

1

pop() is a function and is being indexed as if it were a variable. With a quick look there is an array op which might be what’s needed here. So maybe it should be op[x] and not pop[x] in these places?

And when looking at the original that’s how it is. So a copying error by user, should be closed.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
  • Sorry, could not get your point inspite of best efforts. op[x] is not clear, may be more details needed by me. – jiten Mar 23 '19 at 12:21
  • 1
    @jiten simply: you copied the code wrong. Copy those lines correctly from the source. – Sami Kuhmonen Mar 23 '19 at 12:22
  • I copied the code by writing first on paper twice. Please tell the line nos., as am still unable to find the lines. – jiten Mar 23 '19 at 12:24
  • 1
    @jiten The error messages you provided have the line numbers. Just read the errors and double check – Sami Kuhmonen Mar 23 '19 at 12:25
  • Please see the edited post, with error on compiling with Dev-C++. – jiten Mar 23 '19 at 13:03
  • Please help me considering the edits above. Okay, am new but tried whole night reading posts and compiling on Dev-C++. It hurts me if am not considered genuinely asking inspite of my maximal efforts. – jiten Mar 24 '19 at 00:47