Menu
CoddyTech
Course

C for Dart Developers

Move from Dart to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.

Dart and C side by side

The same program in Dart and in C, from the lessons of this course.

  1. Printing and Comments

    Dart print accepts any object and string interpolation calls toString, so a value is never formatted as the wrong type. C printf trusts its format string: each conversion must match the promoted argument type, and a mismatch is undefined behavior rather than…

    Dart
    1void main() {2  // Interpolation calls toString() on the value.3  int value = 7;4  print('value=$value');5}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10printf("value=%d\n",7);11return 0;12}
  2. Booleans and Branches

    Dart requires every condition to have static type bool: if (s) does not compile for a String, so you test emptiness with isEmpty. C accepts any scalar condition, and a pointer to an empty string is non-null and therefore true.

    Dart
    1void main() {2  String s = '';3  print(s.isEmpty);4}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}
  3. Arrays Need Lengths

    A Dart List is an object that always knows its length, and passing it to a function passes a reference to that same object. C array parameters become pointers, losing the bound; pass a size_t length explicitly rather than looking for a length property.

    Dart
    1void main() {2  List<int> a = [2, 4, 6];3  print(a.length);4}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}
  4. Function Arguments Are Values

    Dart passes every argument by copying a reference to an object into the parameter. int, double and String objects are immutable, and assigning to a parameter only rebinds that local name, so the caller's variable never changes. C also passes values: an int…

    Dart
    1void change(int x) {2  x = 9;3}4
    5void main() {6  var x = 2;7  change(x);8  print(x);9}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}
  5. Addresses and Dereferencing

    Dart never shows you an address. Variables hold references to objects, two variables can alias one object, and the garbage collector keeps it alive as long as anything can reach it; outside dart:ffi there is no address-of operator. C &n takes the address of…

    Dart
    1class Cell {2  int value;3  Cell(this.value);4}5
    6void main() {7  final cell = Cell(2);8  final alias = cell;9  alias.value = 5;10  print(cell.value);11}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}
  6. Parsing with Status Results

    Dart gives you two whole-input checks. int.tryParse returns null unless the text, after trimming surrounding whitespace, is a complete integer, and a RegExp covers the whole string only when you anchor it with ^ and $, because hasMatch searches anywhere. C…

    Dart
    1void main() {2  const text = '12x';3  final digits = RegExp(r'^[0-9]+$');4  print('${digits.hasMatch(text)} ${int.tryParse(text)}');5}
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Source Ports

2 lessons

More courses for Dart developers

Learn C from another language

Frequently asked questions

Who is C for Dart Developers for?

For people who already write Dart and want to learn C. Each lesson starts from Dart you know and shows how C does the same thing, so you skip the beginner basics.

Do I need to know C already?

No. The course starts with your first C program. You need Dart basics: variables, conditions, loops, functions and collections.

How many lessons does C for Dart Developers have?

C for Dart Developers contains 48 interactive lessons you can complete at your own pace.

What does C for Dart Developers cover?

The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.

Is C for Dart Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start C for Dart Developers for free

Get started