Difference between revisions of "C programming notes"

From Wiki at Neela Nurseries
Jump to: navigation, search
m (^ C Pointers and dereference syntax)
m
Line 39: Line 39:
  
 
<!-- comment -->
 
<!-- comment -->
 +
 +
== [[#top|^]] Simple C examples ==
 +
 +
<i>Program 1 - use of C comma operator, a binary operator:</i>
 +
 +
<pre>
 +
#include <stdio.h>
 +
#include <stdlib.h>
 +
 +
 +
 +
// Compile with:
 +
//
 +
//    $ gcc -Wall main.c
 +
//
 +
// As of 2022-06-09 Builds with 'gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0'
 +
 +
 +
 +
 +
int main(int argc, char *argv[])
 +
{
 +
    int z = 3;
 +
 +
    int y[(z++, (z + 1))];
 +
 +
 +
    y[0] = 1;
 +
 +
    if ( z == y[0] ) { }
 +
 +
#define SIZE_OF_160_BYTES (160)
 +
    char lbuf[SIZE_OF_160_BYTES] = { 0 };
 +
    snprintf(lbuf, SIZE_OF_160_BYTES, "2022-06-09 main.c test of C comma operator\narray y[] has size of %lu\n",
 +
      sizeof(y));
 +
    printf("%s", lbuf);
 +
 +
 +
    return 0;
 +
}
 +
 +
</pre>
 +
 +
 +
  
 
== [[#top|^]] References ==
 
== [[#top|^]] References ==
  
 
*  https://en.wikipedia.org/wiki/Duff%27s_device
 
*  https://en.wikipedia.org/wiki/Duff%27s_device
 +
 +
*  https://en.wikipedia.org/wiki/Comma_operator
  
  
  
 
<!-- EOF -->
 
<!-- EOF -->

Revision as of 23:47, 9 June 2022


Really good interesting article by Simon Tatham on co-routines and a couple ways of implementing them in C language; accessible good style of writing:



Quote from the article:

    "Any coding standard which insists on syntactic clarity at the expense of algorithmic clarity should be rewritten."  - Simon Tatham


Floating point convert and notes on-line, Javascript converter:


^ C Pointers and dereference syntax

This section the beginning of references, links and personal notes on some of the most difficult and important C language constructs, often used in schedulers and RTOS implementations:

Arrays of strings and arrays of pointers to strings:


^ Simple C examples

Program 1 - use of C comma operator, a binary operator:

#include <stdio.h>
#include <stdlib.h>



// Compile with:
//
//    $ gcc -Wall main.c
//
// As of 2022-06-09 Builds with 'gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0'




int main(int argc, char *argv[])
{
    int z = 3;

    int y[(z++, (z + 1))];


    y[0] = 1;

    if ( z == y[0] ) { } 

#define SIZE_OF_160_BYTES (160)
    char lbuf[SIZE_OF_160_BYTES] = { 0 };
    snprintf(lbuf, SIZE_OF_160_BYTES, "2022-06-09 main.c test of C comma operator\narray y[] has size of %lu\n",
      sizeof(y));
    printf("%s", lbuf);


    return 0;
}



^ References