Query methods, classes and attributes in the C language

Asked

Viewed 1,740 times

3

I wondered if in the C language and possible query libraries available their modules classes and attributes as in the Python language that exist the methods dir() and help() i am starting to learn C Gora and I am half lost. I will quote an example.

I import the library stdio.h to work with input and output data but I don’t know the modules, variables, or classes that the library has. There is some trick to help me at the time of development?

#include <stdio.h>

int main()
{
  printf("C da depressão :\(\n");
  return 0;
}

2 answers

4


C only have functions, constants, defined types, macros (which disappear before the language itself is processed) and global variables (although rare, because it is unadvisable). One way to find the information is to look at the files header (.h) where you have the statements.

I do not advise trying to learn this way in any language. It is better to look for a more structured way, probably a good book. It is even possible for a person to create his or her own method of study if he or she already has a good programming domain and is strongly self-taught with a proven effectiveness structure. Don’t try to guess what things do, learn what they really do and how to use it. Programming cannot be based on achism, voluntarism and trial and error. Look for the documentation. That’s the trick.

Just to complement, since the question doesn’t talk about it, but the other answer is misleading: C, like Python, has types for all data. C, unlike Python, has types for all variables. The types available by default in C are: char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, _Bool or bool (available in virtually all compilers), struct, union, array and pointer.

There are still some types defined purely in library, among them (not all) size_t, intN_t, int_leastN_t, int_fastN_t, intptr_t, intmax_t, included in <inttypes.h> and <stdint.h>.

Pointers and arrays end up, in a way, getting confused.

Pointers, as well as arrays, are always used in composition with other types. It serves both as a reference for a type, as well as for indicating a sequence of data of its type. The pointer can be composed including functions. The concept of string only exists in the literal between quotes and some functions in <string.h>, at the bottom is just a pointer to char.

It is possible to create your own types, usually through a struct and typedef.

I understand what the other answer meant, but it’s good to make it clear that dict Python has very different semantics than struct. In fact I think an even better comparison would be the Python class with the structure of C. At least in the simplest form of the class, it looks more like a struct, yet it does not give the same guarantees. In fact the way to simulate a class in C is with struct. Simulate a dict requires something even more complex done on its own or using a ready-made library.

1

Language C does not have Classes and/or modules like Python, Java, or C++. The closest to that are structs that resemble the dict python.

Regarding the variables, C has int (inteiro),char (caractere), char* (texto), float (ponto flutuante), long int, and others.

In addition to these types of variables, there are structs that work very similar to objects, so much so that in C++, a struct can represent a class with destroyer builders.

The commands dir() and help(), only exist in python, at least all the other languages I’ve worked with don’t have those functions. In C, you have to look at the documentation, or see the type of input and output value of the methods through the Ides.

  • reading the library header file is kind of boring, and the IDE I use is not very good in that sense I use Codeblocks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.