---
title: "C Programming Language"
id: "26991"
type: "epkb_post_type_1"
slug: "c-programming-language"
published_at: "2024-04-23T10:24:01+00:00"
modified_at: "2024-04-29T21:03:33+00:00"
url: "https://docs.rc.fas.harvard.edu/kb/c-programming-language/"
markdown_url: "https://docs.rc.fas.harvard.edu/kb/c-programming-language.md"
excerpt: "Description C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. By design, C provides constructs that map efficiently to typical machine instructions and has found..."
taxonomy_epkb_post_type_1_category:
  - "Languages"
taxonomy_epkb_post_type_1_tag:
  - "C"
  - "Languages"
---

# C Programming Language

## Description

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. By design, C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to embedded systems. [Wikipedia](https://en.wikipedia.org/wiki/C_(programming_language))

## Best Practice

We recommend jumping to a compute node for compiling a C program as the compilation could take up to few seconds to a minute depending on the complexity of the code. Additionally, it is best to utilize the `test` partition to compile and test a program before executing its production run on the cluster as a batch-job.

It is best practice to compile a C code separately and then use the executable, generated during compilation, in the production run using the `sbatch` script. If possible, avoid including the compilation command in the `sbatch` script, which will recompile the program every time the job is submitted. If any changes are made to the source code, compile the source code separately, and then submit the production run as a batch-job.

## Compilers

You can compile a C code using either a GNU or an Intel compiler.

### GNU gcc compiler

To get a list of currently available GNU compilers on the cluster, execute: `module spider gcc`

The default GNU compiler is typically the latest compiler version on the cluster and can be loaded using `module load gcc`

To compile a code using a specific version of the GNU compiler and the `O2` optimization flag, you can do the following:

`module load gcc/9.5.0-fasrc01`  
 `gcc -O2 -o sum.x sum.c`

### **Intel icc compiler**

To get a list of currently available Intel compilers on the cluster, execute: `module spider intel`

To compile using a specific version of the Intel compiler, execute:

`module load intel/23.0.0-fasrc01`  
 `icc -O2 -o sum.x sum.c`

Note: If loading an intel module version, refer to the following table for compiling your `C` code

| Intel Comiler Version | C | Fortran | C++ |
| --- | --- | --- | --- |
| Below 24.0.0 | icc | ifortran | icpc |
| 24.0.0 and above | icx | ifx | icpx |

If you load an Intel compiler that is lower than version 24.0.0, you might get this remark

`icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.`

This is just a warning that implies that the user of `icc` will be deprecated in the second half of 2023. You can quiet this warning by compiling your code using `icc` in the following manner:

`module load intel/23.0.0-fasrc01`  
 `icc -O2 -diag-disable=10441 -o sum.x sum.c`

## Examples

To get started with C on the Harvard University FAS cluster you can try the example shown on our [User Codes](https://github.com/fasrc/User_Codes/tree/master/Languages/C)
 repository.

## Resources

To learn and practice more in C, see the following:

- **Cprogramming.com** C Tutorial
- [Tutorilaspoint C Tutorial](https://www.tutorialspoint.com/cprogramming/index.htm)

Bookmarkable Links

- [1. Description](#Description)
- [2. Best Practice](#Best_Practice)
- [3. Compilers](#Compilers)
  - [3.1. GNU gcc compiler](#GNU_gcc_compiler)
  - [3.2. Intel icc compiler](#Intel_icc_compiler)

- [4. Examples](#Examples)
- [5. Resources](#Resources)

Last UpdatedApril 29, 2024

Tags: - [C](https://docs.rc.fas.harvard.edu/kb/tag/c/)
- [Languages](https://docs.rc.fas.harvard.edu/kb/tag/languages/)
