: " , " [] ".
, ... C .
, :
.
, .
Peoro . . ".exists" , / . - , , .
:
peoro .exists.
.
#include<stdlib.h> //:for: malloc(...)
#include<stdlib.h> //:for: free(...)
#include <stdio.h> //:for: printf(...)
int main( void ){
printf("[BEG:main]\n");
typedef struct MyStruct{
int whatever;
} MyStruct;
int num = 16;
MyStruct** arr =(
calloc(
1
, sizeof(MyStruct*)*num
)
);;
for(int i = 0; i < num; i+=2 ){
arr[i]= malloc(sizeof(MyStruct));
};;
for(int i = 0; i < num; i++){
if(NULL != arr[i]){
arr[i] -> whatever = i;
};;
};;
for(int i = 0; i < num; i++){
if(NULL != arr[i]){
printf("whatever: %d\n", arr[i] -> whatever);
};;
};;
typedef struct DoublePointersAreTooMuchWork{
int exists;
int mystery_value;
} MyStruct02;
MyStruct02* arr2 = malloc(sizeof(MyStruct02)*num);
for(int i = 0; i < num; i++ ){
if( i%2 ){
arr2[i].exists = 1;
}else{
arr2[i].exists = 0;
};;
};;
for(int i = 0; i < num; i++ ){
if( arr2[i].exists ){
printf("Exists:val:%d\n", arr2[i].mystery_value);
}else{
printf("[Pretend_I_Dont_Exist]\n");
};
}
printf("[END:main]\n");
}
While I'm at it. If you want to run from the command line, name the file "NAE.C99", then create a bash file called "NAE.SH" and paste it into it. Double-click the script to run it, or use "./NAE.SH" where it is located in your git bash terminal.
C=$C"-Werror "
C=$C"-Wfatal-errors "
C=$C"-Wpedantic "
C=$C"-Wall "
C=$C"-Wextra "
C=$C"-std=c99 "
MY_COMMAND_STRING=$C
By the way, this is the code C99 . I am trying to write this while avoiding any particular features of the C99 though.
source
share