in C Language what is Ftell() equivalent on delphi - c

i am working on C source to translate to delphi but i was stuck on reading files on ftell() function, can you help me find the equivalent function in delphi?

If you have an object of type File, then you may use the FilePos() function, described here.

Related

how to analyze a C header file? [duplicate]

This question already exists:
Is it possible to have gcc analyze my code and give me info about it [closed]
Closed 2 years ago.
I want to write a script that analyzes a C header file.
The header contains a few declarations of functions
The scrip needs to understand how many arguments each function has, and what are their types.
can gcc (or other tool) do this?
It comes down to how accurate you want to be when parsing a C header file. You could implement the C grammar for a function declaration and be guaranteed to parse it 100% correctly, but it will be a lot of work.
Conversely, a simple regex matcher is the easiest approach, but could have false-positive matches. You can implement a regex parser using C++, python or even other scripting languages such as bash or powershell. I would suggest python as its beginner friendly.
If you don't know what regex is, it's a simple language used to parse strings and extract data from strings. So you could create a regex expression to find the c function declaration then use that expression to pull out all of the arguments. Should be straight forward.
Create a regex expression on https://regex101.com/ and test it against teat strings, then implement that expression in python to do the work.

Meaning of notation (_()) in C code [duplicate]

I'm here looking at some C source code and I've found this:
fprintf(stderr, _("Try `%s --help' for more information.\n"), command);
I already saw the underscore when I had a look at wxWidget, and I read it's used for internationalization. I found it really horrible (the least intutive name ever), but I tought it's just another weird wxWidget convention.
Now I find it again in some Alsa source. Does anyone know where it comes from?
It comes from GNU gettext, a package designed to ease the internationalization process. The _() function is simply a string wrapper. This function basically replaces the given string on runtime with a translation in the system's language, if available (i.e. if they shipped a .mo file for this language with the program).
It comes from gettext. Originally thought out, internationalization was too long to type each time you needed a string internationalized. So programmers created the shortcut i18n (because there are 18 letters in between the 'i' and the 'n' in internationalization) and you may see source code out there using that. Apparently though i18n was still too long, so now its just an underscore.
That would be from gettext

Calling functions from C (example.i) in TCL code

I have a file called example.i that allows the calling of a number of C functions.
Is it possible to call these functions from my TCL code? I have seen some ways to call C functions from TCL but I found them very hard to understand or incomplete, at least for a TCL rookie such as myself. How can this be done?
The .i suffix suggests you are generating an interface using swig. If so, swig has a -tcl option that should generate code for an extension you can load into Tcl - see Swig page on the Tcl wiki
It's pretty extensively documented already.
See here hello_world and here SWIG for example.

how to print structure value(like gdb ptype) automatically in C?

This question stay in my head for a long time.
As we know, we can easily print data structure in GDB when we debugging, like gdb ptype command, it can output all field value of structure. I know GDB use bfd library to read symbolic information in object file.
My question is: if I want to do this in my C source code, how to do? because I don't want to printf each field of structure one by one. Is there have any exist library to solve this issue?
I think that library will not only meets my requirement, it will be very useful for many others programmers when writing C/C++ code.
As far as C is concerned, such a library cannot exist.
What you can do is write a compiler kind of tool that takes a struct description in some language and generates a header file with struct declarations in C, and a source file with printing code. Such tools do exist (e.g. protobuf-c), but they are mostly geared towards efficient binary serialization, not human-readable representation of C data.
I dont think there are such tools built for C which are widely used. However, you can try to write a function to take the burden and call it when needed. I know a function cannot print all sorts of structure and you've got to build each for each type of struct but it still is a better idea than to just stick to the old rule, write each time.

Lua C: How would I use the Lua source code to create a Lua interpreter that will execute given blocks of Lua code?

I would like to have a detailed explanation.
How would I use the Lua source code to create a Lua interpreter that will execute given blocks of Lua code? The blocks of Lua code would be sent as a char.
you need a call to lua_load to compile the block of code, and then a call to lua_call to run it. For a really good example of how this is done, take a look at the example provided here:.
The first argument to any Lua api function is always an interpreter state, which is the return value of lua_open()
The example actually uses luaL_loadbuffer which wraps the call to lua_load to make compiling a c string a bit easier. you can read how to use it in the chapter of the reference manual that covers the The Auxiliary Library. This leaves a lua chunk at the top of the lua stack, which can then be invoked with lua_call, but the example uses lua_pcall, which provides a bit of error trapping. since the chunk you just compiled doesn't take any arguments (it's a chunk not a function) and doesn't have any return value you'd be interested in, and you want to see the error exactly as it was produced, all of the arguments besides the first (which is always the lua interpreter state) can be zeros.
http://www.lua.org/manual/2.1/subsection3_7_6.html
http://lua-users.org/lists/lua-l/2006-10/msg00405.html an example
http://www.debian-administration.org/articles/264 c++, same type thing
This will tell you how to call Lua from C.

Resources