C/C++

C/C++

C/C++

Your one-stop destination to learn and collaborate about the latest innovations in IBM C/C++ for z/OS compilers to develop high-performing C/C++ applications and system programs on z/OS while maximizing hardware use and improving application performance.

 View Only
  • 1.  Newbie C compile error

    Posted Mon August 19, 2024 02:51 PM

    Hello - 

    I am a total newbie C programmer on z/OS.  I took what seemed to be a simple C program to get my feet wet with using the C compiler on z/OS.  The sample program is supposedly written in K&R standard C.   However, when I try to compile it I get the following errors.   Below is a snippet of the include files along with the errors flagged by the compiler.     It seems that I may be missing one or more includes that contain the definition of "timeval" and "optarg", but I cannot find where they would be.     Any help that you can offer to resolve these errors would be greatly appreciated.  Thanks.

    Regards,

    Perry Shindle

     

    12       |                     

       13       |#include <stdio.h>   

       14       |#include <stdlib.h>  

       15       |#include <string.h>  

       16       |#include <unistd.h>  

       17       |#include <sys/time.h>

       18       |                    

    ...

    ...

    ...

    ...

     125       |int main(argc, argv)                                          

       126       |int argc;                                                     

       127       |char *argvݨ;                                                  

       128       |{                                                             

       129    34 |    long limit = DEFAULT_LIMIT;                               

       130    35 |    int oneshot = 0;                                          

       131    36 |    int print_primes = 0;                                     

       132    37 |    int quiet = 0;                                            

       133    38 |    int seconds = DEFAULT_SECONDS;                            

       134       |    int opt;                                                   

       135    39 |    int passes=0;                                             

       136       |                                                              

       137       |    struct timeval start_time, current_time;                  

     ===========> ...........a...................................................

    *=ERROR===========> a - CCN3007 "struct timeval" is undefined.             

     *=ERROR===========> a - CCN3007 "struct timeval" is undefined.              

       138    40 |    double elapsed_time, total_time = 0;                      

       139    41 |    long prime_count = 0;                                     

       140       |                                                              

       141    42 |    while ((opt = getopt(argc, argv, "l:s:1pq?h")) != -1) {   

       142    43 |        switch (opt) {                                        

       143       |            case 'l':                                         

       144    44 |                limit = atol(optarg);                         

     ===========> .............................a.................................

    *=ERROR===========> a - CCN3045 Undeclared identifier optarg.              

       145    45 |                break;                                        

       146       |            case 's':                                         

       147    46 |                seconds = atoi(optarg);                       

       148    47 |                break;                                        

       149       |            case '1':                                         

       150    48 |                oneshot = 1;                                   

       151    49 |                break;                                        

       152       |            case 'p':                                         

       153    50 |                print_primes = 1;                              

       154    51 |                break;                                        



    ------------------------------
    Perry Shindle
    ------------------------------


  • 2.  RE: Newbie C compile error

    Posted Mon August 19, 2024 03:50 PM

    See Appendix J of this manual:   https://www.ibm.com/docs/en/SSLTBW_2.5.0/pdf/cbcpx01_v2r5.pdf
    Looks like you'll need to define your program as either POSIX or open source  or XPG4.    optarg() is in unistd.h, which you have already included - it just needs the right switch(es) to be pulled in. 



    ------------------------------
    Todd Burch
    ------------------------------