mathiasbynens / mathiasbynens/small

Problems with C file.

Open
#87 0 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
2.3k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

Empty string is the smallest valid c code - it has no executable code and no data, but it remains valid. You can compile it to an object file (.o) and a shared library (.so on UNIX). So the c file in this repo should be an empty file, as this is exactly the smallest valid file of this type.
What you can't do with it, is to link it as a program, as that requires exactly one main function. That is what you're aiming for in the current c file. But there are a few problems with this file (int main;):

  • As mentioned above, this is not the smallest possible c file.
  • The file produces undefined behavior. Normally, main is a function. You've declared main as an int variable. In such case, the C standard AFAIK doesn't specify what happens, although it's permitted (i.e. it's undefined behavior). What a c compiler will typically do in this case, is to put the contents of main in an executable section and call it. This actually allows to run any machine code by assigning an array to main. Anyway, in this case, calling main causes the computer to run machine code consisting of one or more zero bytes (depending on the size of int), which e.g. on my linux x86-64 system causes a segmentation fault. To fix this, you can make main an empty function, by adding {} (returning 0 from main is implicit).
  • The type (int) is not needed, int is an implicit type used in c when none is given. Also, the ending semicolon is not needed as well.
    Given the above, I propose the following:
  • Make c.c an empty file.
  • Add another file, maybe called c_program.c, with the following contents: main(){}.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the repository's c.c file and compare it with the issue's proposed minimal C sources. Make c.c empty and add c_program.c containing the proposed program, then verify that the files meet the stated validity and compilation goals.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.