Author Topic: Understanding C structures  (Read 6316 times)

TWell

  • Member
  • ****
  • Posts: 748
Re: Understanding C structures
« Reply #15 on: September 19, 2016, 01:31:05 AM »
with cl.exe -E someone could clean header a bit.
Code: [Select]
int __cdecl _vscprintf(    const char * _Format, va_list _ArgList);
  int __cdecl _snprintf_c(  char * _DstBuf,   size_t _MaxCount,     const char * _Format, ...);
  int __cdecl _vsnprintf_c(  char *_DstBuf,   size_t _MaxCount,     const char * _Format, va_list _ArgList);

  int __cdecl _fprintf_p(   FILE * _File,     const char * _Format, ...);
  int __cdecl _printf_p(    const char * _Format, ...);
  int __cdecl _sprintf_p(    char * _Dst,   size_t _MaxCount,     const char * _Format, ...);
  int __cdecl _vfprintf_p(   FILE * _File,     const char * _Format, va_list _ArgList);
  int __cdecl _vprintf_p(    const char * _Format, va_list _ArgList);
  int __cdecl _vsprintf_p(    char * _Dst,   size_t _MaxCount,     const char * _Format, va_list _ArgList);
  int __cdecl _scprintf_p(    const char * _Format, ...);
  int __cdecl _vscprintf_p(    const char * _Format, va_list _ArgList);

jj2007

  • Member
  • *****
  • Posts: 9644
  • Assembler is fun ;-)
    • MasmBasic
Re: Understanding C structures
« Reply #16 on: September 19, 2016, 01:39:35 AM »
Interesting! What exactly does that do?

https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx
/E  Copies preprocessor output to standard output.
/EP  Copies preprocessor output to standard output.

adeyblue

  • Member
  • **
  • Posts: 89
    • Airesoft
Re: Understanding C structures
« Reply #17 on: September 19, 2016, 06:13:52 AM »
Quote
Interesting! What exactly does that do?
It evaluates the files according to the command line defines and outputs a resulting .i (text) file so it doesn't contain any pragmas, defines, macros, comments or anything the actual C compiler doesn't need. The difference between /E and /EP is one outputs certain file and line numbers and the other doesn't. You can also add /C to retain the comments.
For instance if you don't have UNICODE defined, you'll get a file full of all the A prototypes and structs, and none of the W ones (except the W only functions).

If stuff actually worked properly, /Zg would dump function prototypes. Except it seems a bit crippled in that it only outputs the last/a random 5 from each include. It's also been removed from the 2015 and above versions.

jj2007

  • Member
  • *****
  • Posts: 9644
  • Assembler is fun ;-)
    • MasmBasic
Re: Understanding C structures
« Reply #18 on: September 19, 2016, 06:58:40 AM »
It evaluates the files according to the command line defines and outputs a resulting .i (text) file

Sample attached.

If stuff actually worked properly, /Zg would dump function prototypes.

VC 2010 Express:
Quote
1>------ Rebuild All started: Project: PlainWin32, Configuration: Debug Win32 ------
1>cl : Command line warning D9035: option 'Zg' has been deprecated and will be removed in a future release
1>  Main.cpp
1>c1xx : fatal error C1048: unknown option 'g' in '-Zg'

Microsoft at its best :eusa_boohoo:

But this looks actually promising, option /EP:
Code: [Select]
1>  ULONGLONG
1>  __stdcall
1>  Int64ShllMod32 (
1>       ULONGLONG Value,
1>       DWORD ShiftCount
1>      );
1> 
1>  LONGLONG
1>  __stdcall
1>  Int64ShraMod32 (
1>       LONGLONG Value,
1>       DWORD ShiftCount
1>      );
1> 

There are over 3000 of them:
Code: [Select]
1>  __stdcall/1>  Int64ShllMod32 (
1>  __stdcall/1>  Int64ShraMod32 (
1>  __stdcall/1>  Int64ShrlMod32 (
1>  __stdcall/1>  Int64ShllMod32 (
1>  __stdcall/1>  Int64ShraMod32 (
1>  __stdcall/1>  Int64ShrlMod32 (
1>  __stdcall/1>  EXCEPTION_ROUTINE (
1>  __stdcall/1>  RtlUnwind (
1>  __stdcall/1>  RtlInitializeSListHead (
1>  __stdcall/1>  RtlFirstEntrySList (
1>  __stdcall/1>  RtlInterlockedPopEntrySList (
1>  __stdcall/1>  RtlInterlockedPushEntrySList (
1>  __stdcall/1>  RtlInterlockedFlushSList (
1>  __stdcall/1>  RtlQueryDepthSList (
1>  __stdcall/1>  RTL_RUN_ONCE_INIT_FN (
1>  __stdcall/1>  RtlRunOnceInitialize (
1>  __stdcall/1>  RtlRunOnceExecuteOnce (
1>  __stdcall/1>  RtlRunOnceBeginInitialize (
1>  __stdcall/1>  RtlRunOnceComplete (
1>  __stdcall/1>  RtlCaptureStackBackTrace(
1>  __stdcall/1>  RtlCaptureContext (
1>  __stdcall/1>  RtlCompareMemory (

Problem is there are only about 3,000 (with #include <windows.h>), while there are about 15,000 in \masm32\include ::)

jj2007

  • Member
  • *****
  • Posts: 9644
  • Assembler is fun ;-)
    • MasmBasic
The CRT is becoming much simpler!
« Reply #19 on: September 28, 2016, 12:49:39 AM »
Good news - Redmond tries to make the CRT simpler:
Quote
The CRT provides 142 different variations of printf ... This 2,696 line file had 223 conditionally compiled regions of code (#ifdef, #else, etc.)

Reminds me of the famous Edsger Dijkstra quote:
Quote
It is practically impossible to teach good programming to students that have had a prior exposure to C++: as potential programmers they are mentally mutilated beyond hope of regeneration.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6589
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Understanding C structures
« Reply #20 on: September 28, 2016, 01:16:11 AM »
 :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Understanding C structures
« Reply #21 on: September 28, 2016, 01:50:36 AM »
https://msdn.microsoft.com/en-us/library/cc230322.aspx

Quote
A DWORD_PTR is an unsigned long type used for pointer precision. It is used when casting a pointer to an unsigned long type to perform pointer arithmetic. DWORD_PTR is also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows.
Well Microsoft, here’s another nice mess you’ve gotten us into.

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: The CRT is becoming much simpler!
« Reply #22 on: September 28, 2016, 02:20:48 AM »
Reminds me of the famous Edsger Dijkstra quote:
Quote
It is practically impossible to teach good programming to students that have had a prior exposure to C++: as potential programmers they are mentally mutilated beyond hope of regeneration.

IMHO if you need a teacher to show you how to code, you never had much potential in the first place.
I am NaN ;)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6589
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Understanding C structures
« Reply #23 on: September 28, 2016, 02:49:18 AM »
> IMHO if you need a teacher to show you how to code, you never had much potential in the first place.  :P
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: