Skip to content

Revise and expand on C/C++ language support section #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5610021
Revise and expand on C/C++ language support section
catamorphism Jul 17, 2025
6d68e09
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
df8a045
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
d47c634
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
1140922
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
b28929a
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
ac98c1a
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
0cf108d
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
09e2c4f
Fix markup in NOTE
catamorphism Aug 6, 2025
014a58c
Fix backtick spacing
catamorphism Aug 6, 2025
dbbf191
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
3be8a7e
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
42746b9
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
c02e274
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
8bbe5bd
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
62ab88e
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
7e553ee
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
b6a4b0b
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
fc58b33
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
c77a855
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
069313a
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
58215c5
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
1869fcf
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
ac9f43b
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
08f6720
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
b93f7d4
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
d6737d5
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
e25ffd7
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
363e7c9
Update component-model/src/language-support/c.md
catamorphism Aug 6, 2025
5bceb22
Indent note about PATH
catamorphism Aug 6, 2025
dc7a784
Minor fixes
catamorphism Aug 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions component-model/examples/tutorial/c/adder/component.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "adder.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've quite intentionally avoided putting other tutorial examples inside this codebase, but I'm thinking we should reconsider that. I'd personally like to see all code we put in the language guides hosted in component-docs so we can at least test them via CI.

That said, this has come up and we decided against it -- maybe I'm misremembering.

Thoughts @itowlson , @kate-goldenring ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my thought -- that if the code examples were in separate files, they could eventually be tested in CI.


uint32_t exports_docs_adder_add_add(uint32_t x, uint32_t y)
{
return x + y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "adder.h"
#include <stdio.h>

uint32_t exports_docs_adder_add_add(uint32_t x, uint32_t y)
{
uint32_t result = x + y;
printf("%d", result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf("%d", result);

We can probably get rid of the stdio.h requirement which allows for more minimal components. adder should technically not need wasi:cli

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the point of including the example that uses printf was to show what happens if you use WASI interfaces and don't include the --adapt flag?

Copy link
Collaborator

@vados-cosmonic vados-cosmonic Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh thank you sorry I lost this context. This would be fine as-is, but what do you think about adding a comment here? Above the printf that explains a little more (and at a glance anyone who sees this file will understand the point of the example).

I'm thinking of a note like:

// On traditional platforms, printf() prints to stdout, but on Wasm platforms
// stdout and the idea of printing to output stream is introduced and managed by
// WASI. 
//
// When building this code with wasi-libc (as a part of wasi-sdk), the printf call
// below is replaced with code that uses `wasi:cli/stdout` and `wasi:io/streams`.

return result;
}
Loading