mathstodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for maths people. We have LaTeX rendering in the web interface!

Server stats:

2.8K
active users

#include

2 posts2 participants0 posts today
Replied in thread
@tatsumoto @nyanide Even a program as trivial as "hello world" is 4MiB in Rust.

Some rust-lover set me this rust program to demonstrate how to get a reasonably-sized hello world in Rust;
#![no_std]
#![no_main]

use core::ffi::CStr;

#[no_mangle]
pub extern fn main(_argc: i32, _argv: *const *const core::ffi::c_char) -> i32 {
unsafe{libc::printf(CStr::from_bytes_with_nul_unchecked("hello world\n\0".as_bytes()).as_ptr());}
0
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_:&core::panic::PanicInfo)->! {
loop{}
}

(Or you can just write in C);
#include <stdio.h>
int main() { printf("hello world\n"); }


Furthermore, the only rust compiler is almost certainly compromised with multiple backdoors, as the only compiler that can compile rust is rustc version N-1.

That's right, if you want to bootstrap rust, you need to bootstrap gcc, then use it to compile an ancient Rust compiler implementation (written in C++) and use that to compile every single Rust version in sequences (requiring hundreds of gigabytes of storage for text and countless CPU cycles).

I'd be highly impressed if no-one managed to slip a backdoor into any of the massive Rust releases from the past several years - I suspect there are several backdoors, as there's plenty of space to fit them in such massive binaries.


Furthermore, the typical Rust program uses hundreds of dependencies, all statically linked.

Rust also often forces you to write 10 times lines to do something that takes 1 line in C.

Remember that most security bugs in software are logic errors (i.e. wrong logic for checking passwords etc) and even if Rust is memory safe and doesn't have memory bugs, you end up with 10x the logic errors and therefore 10x the security bugs, as you have 10x more code.


All that is needed is enhanced static and dynamic analyzers for C - for example there should be an gcc option where it won't compile the GNU C unless the program is free of memory errors and then such could be run on the tried and tested C codebases to tease out the remaining memory bugs - but that software is under a freedom-defending license, thus it must be rewritten under a weak one instead.

As you can see, the Rust cancer needs to be to cut away with a plasma cutter and a corrosion-protective coating applied.
Replied in thread

It looks like CW by default auto-includes any Mac headers you need, but at the same time stdlib stuff like "strlen" isn't working even with a manual #include <strings.h> which is the point where I'm starting to look at "maybe I should read a book instead of just poking at things randomly!" (2/2)

Replied in thread

@jduck I mean, if it convinces you...

$ cat blub.c
#include <stdlib.h>
#include <stdio.h>
struct foo {
long a;
int b;
int arr[];
};
int main(void) {
struct foo *a = malloc(sizeof(struct foo) + sizeof(int)*3);
struct foo *b = malloc(sizeof(struct foo) + sizeof(int)*3);
if (!a || !b)
return 1;

a->a = 1;
a->b = 2;
for (int i=0; i<3; i++)
a->arr[i] = i + 123456;

b->a = 101;
b->b = 102;
for (int i=0; i<3; i++)
b->arr[i] = i + 100;

*b = *a;

for (int i=0; i<3; i++)
printf("%d ", b->arr[i]);
printf("\n");
}
$ gcc -o blub blub.c
$ ./blub
123456 101 102

Why does the C standard not mention any UB in its definition of offsetof()? Is it implicit somewhere else that doing offsetof(struct foo, arr[SIZE_MAX]) on a struct containing a flexible array member is UB?

Both GCC and clang don't diagnose anything here and compile it to a "return 0":

#include <stddef.h>
#include <inttypes.h>
struct foo {
int a;
int arr[];
};
unsigned long func(void) {
return offsetof(struct foo, arr[SIZE_MAX]);
}

godbolt.org/z/rx7rqvh7j

godbolt.orgCompiler Explorer - Cstruct foo { int a; int arr[]; }; unsigned long func(void) { return offsetof(struct foo, arr[SIZE_MAX]); }

Funny standard C behavior - assigning a struct with flexible array member can copy parts of the flexible array member:

$ cat vla_assign.c
#include <stdlib.h>
#include <stdio.h>
struct foo {
long a;
int b;
int arr[];
};
int main(void) {
struct foo *a = malloc(sizeof(struct foo) + sizeof(int)*3);
struct foo *b = malloc(sizeof(struct foo) + sizeof(int)*3);
if (!a || !b)
return 1;

a->a = 1;
a->b = 2;
for (int i=0; i<3; i++)
a->arr[i] = i;

b->a = 101;
b->b = 102;
for (int i=0; i<3; i++)
b->arr[i] = i + 100;

*b = *a;

for (int i=0; i<3; i++)
printf("%d ", b->arr[i]);
printf("\n");
}
$ gcc -Wall -Wextra -pedantic -o vla_assign vla_assign.c
$ ./vla_assign
0 101 102
As a slight distraction, I decided to look at what might be Apple's fork of openrsync:

https://github.com/apple-oss-distributions/rsync

I see xcodeproj crap littered around, yikes! Definitely not how I like to do things, but I guess very Apple-y.

But:

%cd openrsync
%./configure (optionally with PREFIX=/opt/local)

Goes smoothly.

But make breaks with:

% make
cc -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter -c -o batch.o batch.c
In file included from batch.c:31:
In file included from ./extern.h:30:
./md4.h:40:10: error: 'md4.h' file not found with include; use "quotes" instead
40 | #include
| ^~~~~~~
| "md4.h"
./md4.h:51:12: error: unknown type name 'MD4_CTX'; did you mean 'MD5_CTX'?
51 | MD4_Update(MD4_CTX ctx, const void data, size_t len)
| ^~~~~~~
| MD5_CTX
./config.h:150:3: note: 'MD5_CTX' declared here
150 | } MD5_CTX;
| ^
In file included from batch.c:31:
In file included from ./extern.h:30:
./md4.h:60:3: error: call to undeclared function 'MD4Update'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
60 | MD4Update(ctx, data, resid);
| ^
3 errors generated.
make: *** [batch.o] Error 1


(which I think maybe very similar to how the KlaraSystems openrsync fork that stsp@ mentioned broke when I attempted to clone and build it yesterday? Now I am scratchin my head even more. If I had to guess, maybe they both took the FreeBSD openrsync port as a starting point? I am not going to look into this much more deeply at the moment just kind of wondering out loud.)

Yes, I should work on refactoring those MacPorts OpenSSH diffs. I sent a message to the MacPorts Dev mailing list and am hoping someone else will be able to help.

Meanwhile, at least locally I have OpenSSH 10.0 running, so that's good for me? Less good for helping others, but I'm trying not to beat myself up too much at the moment for my temporary failings.
Contribute to apple-oss-distributions/rsync development by creating an account on GitHub.
GitHubGitHub - apple-oss-distributions/rsyncContribute to apple-oss-distributions/rsync development by creating an account on GitHub.
Replied in thread

@thephd
This works to define rsize_t:

#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>

use “xcrun clang -dD -E file.c”, do the same thing with the broken configuration, see where things go wrong. If you do find there’s a problem with the macOS SDK, that sounds fixable

C மொழியின் மாறிகள் | எளிய தமிழில் C பகுதி -6

மாறி என்றால் என்ன? எனக்கு நன்றாக நினைவு இருக்கிறது. நான் ஏழாம் வகுப்பு படித்துக் கொண்டிருக்கும் போது என்னுடைய கணித ஆசிரியர் இந்த பெயரை முதல் முதலாக சொன்னபோது, தனுஷ் நடிச்ச படம் தான் “மாரி” என பின் பெஞ்சிலிருந்த நண்பன் சத்தம் போட்டது இன்றும் நினைவிருக்கிறது. ஒருபுறம் மாறி என்பதையும், மாரி என்பதையும் குழப்பிக் கொண்டவர்கள் பலரும் இருக்கிறார்கள்.

மாரி என்றால் மழை என்று அர்த்தம். மாரி பொழியாது போனால், வையகம் எங்கும் வாடிய பயிர்கள் தான் காணக் கிடைக்கும். ஆனால், சி மொழியில் பார்க்கவிருக்கும் “மாறி” என்பது சற்றே வேறு விதமானது.

முதலில் மாறி என்று சொல்லுக்கான அடிப்படை அர்த்தத்தை புரிந்து கொள்ளுங்கள். மாறுதல் என்பதன் சுருக்கமே மாறி என அறியப்படுகிறது. அப்படி என்றால் இந்த உலகமே மாறுதலுக்குரியதுதான்; அதற்கு C மொழி மட்டும் விதிவிலக்கா என்ன?

ஆங்கிலத்தில் எவ்வித குழப்பமும் இன்றி இதை variables என்று குறிப்பிட்டு விடுவார்கள். அதாவது இதன் மதிப்புகள் மாறிக்கொண்டே இருக்கும். உதாரணமாக, தங்கத்தின் விலையை எடுத்துக் கொள்ளுங்கள் அது நிச்சயமாக ஒரு மாறி மதிப்பு தான். இன்றைக்கு தங்கத்தின் விலை ஒரு லட்ச ரூபாய் என்றால் வரும் நாட்களில் அதன் விலையில் நிச்சயமான ஒரு மாற்றம் இருக்கும்.

C மொழியில் மட்டுமல்ல; உலகில் இருக்கக்கூடிய அனைத்து விதமான நிழலாக்க மொழிகளிலும், மிக முக்கியமான இடத்தை வகிப்பது இந்த மாறி மதிப்புகள் தான். இவற்றினுடைய மதிப்புகள் மாறிக்கொண்டிருக்கும். நீங்கள் வழங்கும் உள்ளீடுகளுக்கு ஏற்ப இவை வெளியீடுகளை வழங்கும்.

சரி! இந்தக் கட்டுரையில் C மொழியில் மாறிகளை எப்படி குறிப்பிட வேண்டும் என்பது பற்றி மட்டும் பார்க்கலாம்.

செய் முறையில் இரண்டு விதமான மாறிகள் இருக்கிறது; ஒன்று எண் அடிப்படையிலான மாறிகள்(numerical based)மற்றும் ஒன்று எழுத்து அடிப்படையிலான(char based)மாறிகள். உதாரணமாக, ஒரு ஓட்டப்பந்தயத்தில் 20 பேர் ஓடிக் கொண்டிருக்கிறார்கள். வினாடிக்கு வினாடி ஒருவரை தாண்டி மற்றொருவர் முன்னேறி வந்து கொண்டே இருக்கிறார். எனவே முன்னேறி சென்று கொண்டிருப்பவரின் பெயர் காண்பிக்கப்பட வேண்டும்(leader board). அதே நேரம், அவரது வீரர் என்னும் குறிப்பிடப்பட வேண்டும். இவ்வாறு புரிந்து வைத்துக் கொள்ளுங்கள்.

ஏற்கனவே C மொழியின் குறிச்சொற்கள் என ஒரு கட்டுரை எழுதி இருக்கிறேன். அந்த கட்டுரையை ஒரு முறை படித்து விடுங்கள்.

அமைப்பு:-(syntax)

கீழ்காணும் வகையில் தான், ஒரு மாறியின் மதிப்பானது சேமிக்கப்பட வேண்டும். முதலில் அந்த மாறியின் வகை வழங்கப்பட்டிருக்க வேண்டும் அதைத் தொடர்ந்து, அந்த மாறியின் பெயர் இடம் பெற்று இருக்க வேண்டும். பின்பு சம குறி இடப்பட்டு மதிப்பு வழங்கப்பட்டிருக்க வேண்டும். முடிவில் அரை நிறுத்த குறிக்கொண்டு முடித்திருக்க வேண்டும்.

type variableName = value;

சரி மதிப்பு அடிப்படையில் உங்களுக்கு புரியும் வகையில் ஒரு சிறிய நிரலாக்கத்தை கீழே வழங்குகிறேன்.

#include<stdio.h>
int main()
{
   int num = 4;
   float car = 5.1;
   char name = ‘car’;
   return 0;
}

மேற்காணும் நிரலாக்கத்தில் முழுஎண் என்பதற்கு 4 என்னும் மதிப்பையும், தசம எண் மதிப்பிற்கு 5.1 , மற்றும் பெயர் என்பதில் car என்றும் கொடுத்திருக்கிறேன். இது போல தான் மாறி மதிப்புகளை நிரலாக்கத்தில் எழுத வேண்டும். ஆனால், அடுத்தடுத்த வரிகளில் செல்ல செல்ல இந்த மாறிகளின் மதிப்புகளும் மாறிக்கொண்டே இருக்கும். மாறிக்கொண்டே இருக்கும் இந்த மாறியின் மதிப்புகளை மாற்றி மாற்றி விளையாடுவது எப்படி என அடுத்து வரும் கட்டுரையில் இனிதே காணலாம்.

மீண்டும் ஒரு இனிய தமிழில் C கட்டுரையில் சந்திப்போம்.

கட்டுரையாளர்:-

ஸ்ரீ காளீஸ்வரர் செ,
இளங்கலை இயற்பியல் மாணவர்,
(தென் திருவிதாங்கூர் இந்துக் கல்லூரி, நாகர்கோவில் – 02)
இளநிலை கட்டுரையாளர் மற்றும் மொழிபெயர்ப்பாளர்,
கணியம் அறக்கட்டளை.
மின்மடல் : srikaleeswarar@myyahoo.com
இணையம்: ssktamil.wordpress.com

SRI KALEESWARAR SSRI KALEESWARAR SThe reality comes from here

C மொழியில் அடுத்த வரிக்கு செல்வது எப்படி? | எளிய தமிழில் சி பகுதி 5

வழக்கமாக, பள்ளி- கல்லூரியில் ஆசிரியர் சொல்ல,சொல்ல மாணவர்கள் குறிப்பெடுத்து கொண்டிருக்கும் போது, இந்த வரியை அடுத்த பத்தியாக(para) எழுத வேண்டும் என ஆசிரியர் கூறுவார். அல்லது இந்த இடத்தில் மேற்கோள் குறி இட வேண்டும்(“) என்று குறிப்பிடுவார்.

இந்த அடிப்படையான வேலைகளை கணினியின் அடிப்படை மொழியான C யில் எப்படி செய்வது? என்று தான் இன்றைக்கு பார்க்கவிருக்கிறோம்.

ஏற்கனவே, printf() செயல்பாட்டின் மூலம் நீங்கள் கொடுக்கும் உள்ளீடை, வெளியீட்டு திரையில் காண்பிக்க முடியும் என பார்த்து இருந்தோம். அதேபோல, /n எனும் குறியை மேற்குறிபட்ட செயல்பாட்டுக்குள் வழங்குவதன் மூலம் அடுத்து வரிக்கு(next line)செல்ல முடியும்.

#include <stdio.h>

int main() {
  printf(“Hello Kaniyam!\n”);
  printf(“I am writing about C.”);
  return 0;
}

Output:-

Hello Kaniyam

I am writing about C.

மேற்கண்ட இந்த நிரலில்  ஹலோ கணியம் என்பதற்கு அடுத்ததாக \n வழங்கப்பட்டுள்ளது. இதன் காரணமாக, அதைத்தொடர்ந்து வழங்கப்பட்டிருக்கும் உரையானது, அடுத்த வரியில் வெளியீடாக வழங்கப்படும். ஆனால் இங்கு கவனிக்க வேண்டியது என்னவென்றால்,  \n என்பதையும் மேற்கோள் குறிகளுக்குள் (quotation marks)தான் வழங்க வேண்டும். தனியாக வழங்கினால் வேலை செய்யாது.

#include <stdio.h>

int main() {
  printf(“Hello kaniyam!\nI am writing about C.\nAnd it is awesome!”);
  return 0;
}

Output:-

Hello Kaniyam!
I am writing about C.
And it is awesome!

மேற்கண்ட நிரலில், ஒரே printf() செயல்பாட்டிற்குள்ளாக இரண்டு புதிய வரிக்கான கட்டளைகள் பிறப்பிக்கப்பட்டிருக்கிறது. இதன் மூலம், ஒரே செயல்பாட்டில் நம்மால் மூன்று வரிகளை அச்சடிக்க முடியும். இந்த இடத்திலும் கூட மேற்குறிகளுக்கு உள்ளாகத்தான் \n என எழுத வேண்டும்.

#include <stdio.h>

int main() {
  printf(“Hello World!\n\n”);
  printf(“I am learning C.”);
  return 0;
}

Output:-
Hello World!

I am learning C.

இந்த நிரலிலோ, சற்று வித்தியாசமாக ஒரே வரியில் இரண்டு புதிய வரி கட்டளைகள் வழங்கப்பட்டுள்ளது. இவ்வாறு செய்யும் போது, முதல் கட்டளை ஆனது அடுத்த வரிக்கு அழைத்துச் செல்லும். அதே நேரம் அதை தொடர்ந்து வரும் மற்றொரு கட்டளையானது, ஒரு வெற்று வரியை ஏற்படுத்தும். இதனால், நீங்கள் ஒருவரை விட்டு மற்றொரு வரி எழுதுவதற்கு இந்த முறையை பயன்படுத்தலாம். முன்பு பார்த்தது போல, ஒரே செயல்பாட்டிற்குள்ளவும் ஒரு வரி விட்டு எழுதுவதற்கு இதை பயன்படுத்தலாம். இது போல, எத்தனை வரிகளை வேண்டுமானாலும் விட்டு எழுதலாம்.

#include <stdio.h>

int main() {
  printf(“Hello World!\t”);
  printf(“I am learning C.”);
  return 0;
}

Output:-
Hello World!    I am learning C.

\t இன்னும் உள்ளீடை பயன்படுத்துவதன் மூலம் நேர்கோட்டில் ஐந்து எழுத்து அளவிற்கு(5 space )இடைவெளி விட்டு எழுதுவதற்கு இது பயன்படுகிறது. இதற்கான மாதிரி நிரலாக்கம் மேலே வழங்கப்பட்டுள்ளது.

#include <stdio.h>

int main() {
  printf(“House number 55\\”);
  printf(“101,north street.”);
  return 0;
}
Output:-
House number 55\101,north street.

உதாரணமாக, ஒரு வீட்டின் பழைய எண் புதிய எண் போன்றவற்றை எழுதுவதற்கு \ குறியை பயன்படுத்துவோம். ஆனால், சீமொழியில் இப்படி பயன்படுத்துவதற்கு \\ என உள்ளீடு வழங்க வேண்டும். இதன் மூலம், மேற்கண்டவாறு எளிமையாக வீட்டு எண் போன்ற \ or/ தேவைப்படும் எழுத்துக்களை திரையில் எழுதலாம்.

include <stdio.h>

int main() {
  printf(“Welcome to \”kaniyam\”.”);
  return 0;
}

Output:-

Welcome to “kaniyam”.

நாம் C மொழியில் ஒரு எழுத்தை அச்சிட வேண்டும் என்றால், மேற்கோள் குறிகளை பயன்படுத்த வேண்டி இருக்கிறது. ஆனால், அப்படி அச்சிடும் எழுத்துக்களுக்கும், மேற்கோள் பயன்படுத்த வேண்டி இருந்தால் என்ன செய்வது? எனும் சந்தேகம் உங்களுக்கு இருக்கலாம்.\” எனும் குறியை மேற்கோள் குறியிட வேண்டிய எழுத்தின் முன் பின் எழுதுவதன் மூலம், மேற்கண்ட நிரலில் இருப்பது போல குறிப்பிட்டு எழுத்திற்கு மேற்கோள் குறியிட முடியும்.

C மொழியின் சில அடிப்படையான எழுத்து பயிற்சிகள் குறித்து இந்த கட்டுரை மூலம் அறிந்து கொண்டிருப்பீர்கள் என்று நம்புகிறேன்.

மீண்டும் ஒரு எளிய தமிழில் C பகுதியில் சந்திக்கலாம்.

Reference: W3schools

கட்டுரையாளர்:-

ஸ்ரீ காளீஸ்வரர் செ,
இளங்கலை இயற்பியல் மாணவர்,
(தென் திருவிதாங்கூர் இந்துக் கல்லூரி, நாகர்கோவில் – 02)
இளநிலை கட்டுரையாளர் மற்றும் மொழிபெயர்ப்பாளர்,
கணியம் அறக்கட்டளை.
மின்மடல் : srikaleeswarar@myyahoo.com
இணையம்: ssktamil.wordpress.com

SRI KALEESWARAR SSRI KALEESWARAR SThe reality comes from here
Replied in thread

@whitequark @ronya That is wild because the whole reason for that separate parser is to be able to reindex individual files without paying attention to the #include graph or anything.

It doesn't do this for me, but that's using "full" VS, which shares the parser(s) but not the layer that orchestrates them. (But also both VS and Code are prone to behaving in similarly broken ways.)

inspired by @pinskia mentioning musttail, today I learned that you can implement state machines in C such that state transitions are implemented as calls:

#include <stdlib.h>
#include <stdio.h>

#define VOID __attribute__((noinline)) void
#define JUMP [[clang::musttail]] return

static char *input;
static int acc = 0;
static int state = 0;

VOID initial_state(void);

VOID digit(void) {
acc += *(input++) - '0';
JUMP initial_state();
}
VOID separator(void) {
state = acc;
acc = 0;
input++;
JUMP initial_state();
}
VOID add(void) {
state += acc;
acc = 0;
input++;
JUMP initial_state();
}
VOID minus(void) {
state -= acc;
acc = 0;
input++;
JUMP initial_state();
}

VOID initial_state(void) {
switch (*input) {
case '0'...'9':
JUMP digit();
case ' ':
JUMP separator();
case '+':
JUMP add();
case '-':
JUMP minus();
default:
printf("result: %d\n", state);
exit(0);
}
}

int main(int argc, char **argv) {
puts("welcome to my calculator");
input = argv[1];
initial_state();
}

compiles to stuff like this, all jumps:

add:
mov eax, dword ptr [rip + acc]
add dword ptr [rip + state], eax
mov dword ptr [rip + acc], 0
inc qword ptr [rip + input]
jmp initial_state

And the security benefits are obvious! The less stack you have, the less potential for the stack pointer being hijacked! 😆

Replied in thread

@RustyCrab @prettygood

/* Exit with a status code indicating success.
   Copyright (C) 1999-2025 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include "system.h"

/* Act like "true" by default; false.c overrides this.  */
#ifndef EXIT_STATUS
# define EXIT_STATUS EXIT_SUCCESS
#endif

#if EXIT_STATUS == EXIT_SUCCESS
# define PROGRAM_NAME "true"
#else
# define PROGRAM_NAME "false"
#endif

#define AUTHORS proper_name ("Jim Meyering")

void
usage (int status)
{
  printf (_("\
Usage: %s [ignored command line arguments]\n\
  or:  %s OPTION\n\
"),
          program_name, program_name);
  printf ("%s\n\n",
          _(EXIT_STATUS == EXIT_SUCCESS
            ? N_("Exit with a status code indicating success.")
            : N_("Exit with a status code indicating failure.")));
  fputs (HELP_OPTION_DESCRIPTION, stdout);
  fputs (VERSION_OPTION_DESCRIPTION, stdout);
  printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
  emit_ancillary_info (PROGRAM_NAME);
  exit (status);
}

int
main (int argc, char **argv)
{
  /* Recognize --help or --version only if it's the only command-line
     argument.  */
  if (argc == 2)
    {
      initialize_main (&argc, &argv);
      set_program_name (argv[0]);
      setlocale (LC_ALL, "");
      bindtextdomain (PACKAGE, LOCALEDIR);
      textdomain (PACKAGE);

      /* Note true(1) will return EXIT_FAILURE in the
         edge case where writes fail with GNU specific options.  */
      atexit (close_stdout);

      if (STREQ (argv[1], "--help"))
        usage (EXIT_STATUS);

      if (STREQ (argv[1], "--version"))
        version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
                     (char *) nullptr);
    }

  return EXIT_STATUS;
}
darkdork.devDarkDork.dev
#include#ifndef#if

C மொழியின் குறிப்புகள்(comments) | எளிய தமிழில் C பகுதி 4

ஒவ்வொரு மொழியிலும் நிரலாக்கம் எழுதும்போது எந்த அளவிற்கு சரியாக எழுதுகிறோமோ, அந்த அளவிற்கு வரிக்கு வரி அதை விளக்கும் விதமான குறிப்புகளை வழங்கிக் கொண்டே வரவேண்டும்.

ஆங்கிலத்தில் இதை கமெண்ட் என அறியப்படுகிறது. எப்படி சமையல் செய்யும்போது சமையல் குறிப்புகள் பயன்படுகிறதோ, அது போலவே நிரலாக்கத்தின் போதும் குறிப்புகளை வழங்க வேண்டும். நீங்கள் ஒரு நிறுவனத்தில் குறுகிய காலம் பணியாற்றி விட்டு வெளியில் செல்ல கூடும். அப்படி வெளியில் செல்லும்போது, உங்களுக்குப் பிறகு அதே வேலைக்கு வருபவர் இதே நிரலாக்கத்தை பயன்படுத்தி தான் வேலைகளை தொடர வேண்டி இருக்கும்.

மேலும் என்னதான் இதை நீங்கள் நிரலாக்கத்திற்குள் எழுதினாலும், நிரலாக்கத்திற்கும், குறிப்புகளுக்கும் எவ்வித சம்பந்தமும் கிடையாது. நீங்கள் எத்தனை வரிகளுக்கு குறிப்பு எழுதினாலும், நிரலாக்கத்தோடு சேர்ந்து அவை இயக்கப்படுவதில்லை, வெளியீட்டிலும் காண்பிக்கப்படுவதில்லை. மாறாக,மூல பிரதியில்(source code)மட்டும்தான் குறிப்புகள் இடம்பெற்றிருக்கும். எனவே இதனால் எவ்வித சிக்கல்களும் கிடையாது. மேலும்,இந்த குறிப்புகள் பயனர்களுக்காக வழங்கப்படவில்லை. மாறாக, சக நிரலாக்க கலைஞர்களுக்காகவே வழங்கப்படுகிறது என்பதையும் நினைவில் வைத்துக் கொள்ளுங்கள்.

உங்களுக்குப் புரிந்தது என்பதற்காக அதே வகையிலான நிரலாக்கம் அவருக்கும் புரிய வேண்டிய அவசியமில்லை. உங்களுடைய நுணுக்கங்கள் அவருக்கு புரியாது போகும் பட்சத்தில், நிறுவனம் மிகப்பெரிய சிக்கலை சந்திக்கும். ஏன்? நாம் கூட குறுகிய காலத்திலேயே எதற்காக இந்த வரியை எழுதினோம் என மறந்துவிடக்கூடும். பிறகு நாமே அதை தேடி கண்டுபிடித்து திருத்துவதற்கு ஒரு நாள் முழுவதும் விழிப்புதுங்கிக் கொண்டிருக்க வேண்டும்.

இது போன்ற பிரச்சனைகளை தவிர்ப்பதற்காக தான், நிரலாக்க மொழிகளில் குறிப்புகள் பயன்படுத்தப்படுகிறது. முதன்மையான மற்றும் பழமையான நிரலாக்க முறையாக அறியப்படும் c மொழியில் நீங்கள் இரண்டு வகையில் குறிப்புகளை வழங்க முடியும்.

C மொழியின் 1999 ஆம் ஆண்டு பதிப்பு வரை, குறிப்பிட்ட ஒரு வகையில் மட்டுமே உங்களால் குறிப்புகளை பதிவு செய்ய முடிந்தது. தற்போது உங்களுக்கு இரண்டு வழிமுறைகள் இருக்கின்றன.

ஒரு வரி குறிப்புகள் (single line comments)

ஒரு வரி குறிப்புகள் என்பது, ஒரு நிரல் ஆக்கத்தின் குறிப்பிட்ட பகுதியில் ஒரு வரி விளக்கம் தேவைப்படும் போது அதை வழங்குவதற்கு இது போதுமானது. உதாரணமாக, புதியதாக படிக்கின்ற மாணவர்களுக்கு இது போன்ற ஒருவரி குறிப்புகள் மிகவும் பயனுள்ளதாக இருக்கும். மேலும் குறிப்பிட்ட எந்த வரியில் இருந்து இந்த இதற்கான வெளியீடு கிடைக்கிறது என்று கூட ஒரு வரியில் எழுதி முடித்து விடலாம். // எனும் குறிதான்(double slace)ஒரு வரி குறிப்புகளுக்காக பயன்படுத்தப்படுகிறது.

உதாரணமாக,

#include<stdio.h>
using namespace std;
int main()
{
  // This is my name
printf(“my name is sri”);
return 0;
}

இந்த இடத்தில் ஒரு வரியில், இந்த நிரல் ஆக்கமானது என்னுடைய பெயரை அச்சிடுகிறது என்று கூறுவதற்காக குறிப்புகளை நாம் பயன்படுத்தி இருக்கிறோம்.

பல வரி குறிப்புகள் (multiline comments)

ஒரு வரி குறிப்புகளை எழுதும்போது தொடக்கம் மட்டும் போதும் அதை முடித்ததாக குறிப்பிட வேண்டிய அவசியமில்லை. ஆனால் பல வரி குறிப்புகளை தொடங்கி அதுபோலவே முடிக்கவும் வேண்டும். /* எனத் தொடங்கும் பல வரி குறிப்புகள் */ என முடிய வேண்டும்.

#include<stdio.h>
using namespace std;
int main()
{
  /* This is a multi line comment written by srikaleeswarar at kaniyam c article */
printf(“my name is sri”);
return 0;
}

இருந்த போதிலும் கூட, குறிப்புகள் எழுதும்போது மிகவும் கவனமாக இருக்க வேண்டும். தவறாக குறிப்புகள் எழுதி விட்டால் நீங்கள் எழுதி இருக்கும் ஒட்டுமொத்த நிரலாக்கமும் பிழை என ஆகிவிடும். மேலும், பல வரி குறிப்புகளை எழுதும்போது அதை முறையாக நிறைவு செய்தல் வேண்டும். மேலும், ஒவ்வொரு நிரலாக்க கலைஞரும் குறிப்புகள் எழுதும் பழக்கத்தை வளர்த்துக் கொள்ள வேண்டும். இது பிறருக்கு உதவுவதோடு சிக்கலான தருணங்களில் நிரல் ஆக்கத்தை பிரித்து வேலை பார்ப்பதற்கும் உதவும்.

மீண்டும் ஒரு சி கட்டுரையில் சந்திப்போம்.

கட்டுரையாளர்:-

ஸ்ரீ காளீஸ்வரர் செ,
இளங்கலை இயற்பியல் மாணவர்,
(தென் திருவிதாங்கூர் இந்துக் கல்லூரி, நாகர்கோவில் – 02)
இளநிலை கட்டுரையாளர் மற்றும் மொழிபெயர்ப்பாளர்,
கணியம் அறக்கட்டளை.
மின்மடல் : srikaleeswarar@myyahoo.com
இணையம்: ssktamil.wordpress.com

SRI KALEESWARAR SSRI KALEESWARAR SThe reality comes from here
Replied to Jann Horn

@jann I mean equally:

#define _GNU_SOURCE
#include <err.h>
#include <stdio.h>
#include <sys/mman.h>
int main(void) {
char *p = mmap(NULL, 0x2000, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) err(1, "mmap");
p[0x1000] = 'X';
if (madvise(&p[0x1000], 0x1000, MADV_DONTNEED)) err(1, "madvise");
// that 'X' we just wrote... is it gone?
// nope, let's bring it back!
printf("p[0x1000]='%c'\n", p[0x1000]);
}

fun Linux fact: because MAP_SHARED|MAP_ANONYMOUS is actually a file-backed mapping under the hood, unmapping part of such a mapping does not discard the data stored in that part:

$ cat mremap.c
#define _GNU_SOURCE
#include <err.h>
#include <stdio.h>
#include <sys/mman.h>
int main(void) {
char *p = mmap(NULL, 0x2000, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) err(1, "mmap");
p[0x1000] = 'X';
if (munmap(p+0x1000, 0x1000)) err(1, "munmap");
// that 'X' we just wrote... is it gone?
// nope, let's bring it back!
p = mremap(p, 0x1000, 0x2000, MREMAP_MAYMOVE);
if (p == MAP_FAILED) err(1, "mremap");
printf("p[0x1000]='%c'\n", p[0x1000]);
}
$ gcc -o mremap mremap.c
$ ./mremap
p[0x1000]='X'
$

Many file formats have some kinds of inclusion directive, like "" for C, "\input" for LaTeX, "\transclude" for forester, "import" for many programming languages.

I would like to have a text editor feature that allows me to visually expand an inclusion directive in the text buffer, just like how folds of text regions work, while actual changes are still made to the referenced file.

This would be very useful when working with projects with many inter-linked files because most text editors are not very good at jumping around files/buffers.
However, this feature looks impossible to implement nicely in vim. Does anyone know an editor that supports this or is hopeful to support this?