#VSCode and C

166 messages · Page 1 of 1 (latest)

visual pumice
#

You need to install a compiler bro

oak gazelleBOT
#

@rich hornet has reached level 4. GG!

visual pumice
#

Ok

#

Did you install c/cpp extension

#

Ok when you click the green button its going to tell you to choose compiler

#

As far as i know gcc is for C

#

And g++ is for C++

#

Play button on the top right

#

Try switching to another file and going back to the source file it gets hidden sometimes

#

Or you messed something up while trying to setup C on VSC 💀

#

Oh you dont know how to use vsc 😭

#

Well there should be a green ▶️ button

#

That compiles and runs the code

visual pumice
#

Bro send ss 💀

#

Bruh i dont remember such a thing

oak gazelleBOT
#

@visual pumice has reached level 49. GG!

visual pumice
zinc rose
#

show a screenshot of your full window please

#

your running button is on the top right, it's just not green 🙂

#

left to the settings icon

#

select the first one

young patio
#

here's a thought: compile via command line 👍

zinc rose
#

is gcc in path?

#

cmd -> gcc --version

#

then click on open launch.json

#

but it opened a json 👀

#

good

#

what?

#

lol

#

find the json in your directory

zinc rose
#

in your .vscode folder

oblique ingot
#

erm

#

dont use vscode

#

simple

hot vault
#

you can just open a console and compile by cc

#

or clang

oblique ingot
#

install mingw

#

and shit

hot vault
#

at this point just use vim/nvim/emacs

zinc rose
#

did you open a file or folder in vscode?

oblique ingot
#

cmake sucks

zinc rose
#

classic case of skill issue

past perch
worthy timber
#

ming's is gaA use WSL, already built into windows

oak gazelleBOT
#

@worthy timber has reached level 4. GG!

hushed goblet
oblique ingot
#

cmake is baddddd

spiral isle
#

@oblique ingot How does your contribution to this chat help getting the issue solved? It's annoying for the questioner if the topic of the help-post gets changed...

zinc rose
#

can you send me a screenshot of your projects folder please?

visual pumice
#

why is there a random void parameter

young patio
visual pumice
#

strange

#

because VOID can also be used to express any datatype

#

i might however be wrong

#

personally i use only c++

#

i also dont think you can pass random arguments unless you do args[] i thought?

#

which would mean any arguement

#

@young patio

#

like
int main(args[])

young patio
visual pumice
#

shoot bro

#

ive been

#

working with windows api

#

for

#

8 hours straight

#

my bad lolz

#

i think im going insane hah

young patio
#

void is what's known as the type-0 because it there's no value of that type

#

unlike say a bool which has two possible values

visual pumice
#

yeah, 1 or 0

young patio
#

here's an example:

#include <stdio.h>

int foo();

int main(void){
    printf("%d\n", foo(2, 3, 4));
    return 0;
}

int foo(int a, int b){
    return a + b;
}
#

this compiles in c just fine

mellow pagodaBOT
#
Program Output
5
visual pumice
#

: (

#

use struct

#

pls

#

🙏

young patio
#

wym struct?

visual pumice
#

typedef struct to store a and b

visual pumice
#
typedef struct(
  int a;
  int b;
) numberos;
mellow pagodaBOT
#
Compiler Output
<source>: In function 'int main()':
<source>:6:23: error: too many arguments to function 'int foo()'
    6 |     printf("%d\n", foo(2, 3, 4));
      |                    ~~~^~~~~~~~~
<source>:3:5: note: declared here
    3 | int foo();
      |     ^~~
Build failed
young patio
visual pumice
#

yeah but its always good practise

#

when it comes to larger programs

young patio
#

i mean, it depends

#

if there's a good reason to pack everything into a struct, then yeah

visual pumice
#

well, i only use it because i work with low level windows internals

#

i personally

#

like

#

neat code

young patio
#

like for example a cartesian point would make sense

visual pumice
#

anything where you need to store a ton of data types

young patio
#

but like a function that computes the greater of two integers not so much

oblique ingot
young patio
#

the hell do you mean?

oblique ingot
visual pumice
#

you don’t pass an arguement to yourself lol

dreamy falcon
#

I knew that not listing parameters was declaring that any params could be passed, but I didn’t know the definition didn’t have to exactly match.

young patio
#

the difference is actually clearer when you understand the different between parameter type lists and identifier lists:

// using parameter type lists

// a declaration
int max(int a, int b);

// a definition
int max(int a, int b){
  //...
}


// using identifier lists

// a declaration
int max2(); 

// a definition
int max2(a, b) int a; int b; {
  //...
}

using identifier lists, the declaration can't specify it's parameters, meaning such declaration only says that max2 returns an int but may take in any number of arguments of any type, they're just not known

#

keep in mind that max2 can therefore be called using any number of arguments but it's undefined behavior to do so

oak gazelleBOT
#

@rich hornet has reached level 5. GG!

zinc rose
#

there is the .vscode folder i was talking about

visual pumice
#

@rich hornet i strongly reccomend just using visual studio

#

visual studio is better anyway

#

i reccomend swapping

#

visual studio also allows you to easily install development kits, far better than VSC

zinc rose
visual pumice
#

a better IDE in general

#

i only use VSC for high level programming

zinc rose
#

vscode is no ide

visual pumice
#

in context, it’s being used as one

#

so

#

vs is better

#

it takes up more space but it also has literally everything you could possibly need

zinc rose
brazen ocean
young patio
#

the wikipedia page mentions the () unit type in haskell as similar but in fact that type has one possible value:

void :: ()
void = ()
hushed goblet
young patio
#

i tested this in ghci and it works

#

() is a value of type ()

#

wonky, I know

visual pumice
#

use visual studio

zinc rose
#

what's the exact reason again why you are not using visual studio?

#

when you try to run in vscode without a conf then it creates one

#

and you can modify it to compile and run your code

zinc rose
#

but visual studio is easier to get started as a beginner so good for you when you are lazy 🤔

#

you can make it execute a bash command as soon as you click on the start icon

#

same as when you would compile and start with your terminal

hushed goblet
zinc rose
#

but you can just use what you need

#

i don't like visual studio that much myself to be honest

#

yes, you have to set this up in your configuration file

karmic imp
#

@rich hornet çözdünmü sorunu

karmic imp
#

ire fotodan

dreamy falcon
young patio
young patio
#

yeah

#

originally the creators of C thought it was too much of a hassle having to specify the type in paremeter lists

#

so this exists purely for backwards compatability

hot vault
brazen ocean
young patio
brazen ocean
#

I've learned C++ first, all I know about C is from experimenting and looking at golf programs from others 😄

#

But I can still write a 5 characters valid program in C, which compiles, runs and generates a segfault 😄

young patio
#

5? including int main()?

brazen ocean
#

5 characters in total, including everything

young patio
#

care to show? lol

brazen ocean