Random in C++

hi,
We want to write a random function in C++ language and put into a header file . But the copiler don’t recoginize the C++ language and show us error . I want to know if it eclipse support the C++ language ?

#ifndef AD_ADCHANDLER_H_
#define AD_ADCHANDLER_H_
#include <iostream>
#include <cstdlib>
ascii word[100];
void main(){ 
 srand((unsigned)time(/0)); 
    int random_integer; 
    
        random_integer = (rand()%10)+1; 
      
    switch(random_integer)
    {
         case 0 :word[100]="+ADC: 4145,1393,1376\nOK";
         break;
         case 1 :word[100]="+ADC: 4140,1390,1375\nOK";
         break;
         case 2 :word[100]="+ADC: 4141,1395,1378\nOK";
         break;
         case 3 :word[100]="+ADC: 4146,1399,1372\nOK";
         break;
         case 4 :word[100]="+ADC: 4145,1393,1375\nOK";
         break;
         case 5 :word[100]="+ADC: 4142,1394,1376\nOK";
         break;
         case 6 :word[100]="+ADC: 4140,1393,1375\nOK";
         break;
         case 7 :word[100]="+ADC: 4145,1393,1378\nOK";
         break;
         case 8 :word[100]="+ADC: 4143,1399,1374\nOK";
         break;
         case 9 :word[100]="+ADC: 4145,1396,1378\nOK";
         break;
    }
    }

#endif /*AD_ADCHANDLER_H_*/

Is there any document we can get to be a reference for us?
Best Regards,
thia

The Open-AT SDK is specifically described and configured as an ANSI ‘C’ environment - not C++

There are plenty of threads on adapting Open-AT for C++ if you want to do it…

Eclipse is a general IDE - it can be configured for many different languages…

But why do you say you need C++ :question:

I don’t think there was anything in the code you posted that requires C++ rather than just ANSI ‘C’ - is there?

That is impossible.

You cannot write a truly random function in any programming language!

A programming language is a deterministic list of instructions - so it can never give a truly random output!

The best you can get is a pseudo-random output.

No, you should certainly not put the function itself into a header file! :open_mouth:

Doing that is a sure way to get lots of Linker errors - complaining about multiple definitions of your function(s) for every file that includes your header!

Only the function prototype should go in the header - the function itself should be in a separate source file and/or a library file

See: c-faq.com/decl/decldef.html

I’ve just received this in an email newsletter:

So, If you want to learn about Eclipse, why not take a look at some of these articles: